QXmlSimpleReader Class ReferenceThe QXmlSimpleReader class provides an implementation of a simple XML parser. More... #include <QXmlSimpleReader> Inherits: QXmlReader. Warning: This class is not reentrant. Public Functions
Reimplemented Public Functions
Detailed DescriptionThe QXmlSimpleReader class provides an implementation of a simple XML parser. This XML reader is suitable for a wide range of applications. It is able to parse well-formed XML and can report the namespaces of elements to a content handler; however, it does not parse any external entities. For historical reasons, Attribute Value Normalization and End-of-Line Handling as described in the XML 1.0 specification is not performed. The easiest pattern of use for this class is to create a reader instance, define an input source, specify the handlers to be used by the reader, and parse the data. For example, we could use a QFile to supply the input. Here, we create a reader, and define an input source to be used by the reader: QXmlSimpleReader xmlReader; QXmlInputSource *source = new QXmlInputSource(file); A handler lets us perform actions when the reader encounters certain types of content, or if errors in the input are found. The reader must be told which handler to use for each type of event. For many common applications, we can create a custom handler by subclassing QXmlDefaultHandler, and use this to handle both error and content events: Handler *handler = new Handler; xmlReader.setContentHandler(handler); xmlReader.setErrorHandler(handler); If you don't set at least the content and error handlers, the parser will fall back on its default behavior---and will do nothing. The most convenient way to handle the input is to read it in a single pass using the parse() function with an argument that specifies the input source: bool ok = xmlReader.parse(source); if (!ok) std::cout << "Parsing failed." << std::endl; If you can't parse the entire input in one go (for example, it is huge, or is being delivered over a network connection), data can be fed to the parser in pieces. This is achieved by telling parse() to work incrementally, and making subsequent calls to the parseContinue() function, until all the data has been processed. A common way to perform incremental parsing is to connect the readyRead() signal of a network reply a slot, and handle the incoming data there. See QNetworkAccessManager. Aspects of the parsing behavior can be adapted using setFeature() and setProperty(). xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true); QXmlSimpleReader is not reentrant. If you want to use the class in threaded code, lock the code using QXmlSimpleReader with a locking mechanism, such as a QMutex. Member Function Documentation
|
Feature | Default | Notes |
---|---|---|
http://xml.org/sax/features/namespaces | true | If enabled, namespaces are reported to the content handler. |
http://xml.org/sax/features/namespace-prefixes | false | If enabled, the original prefixed names and attributes used for namespace declarations are reported. |
http://trolltech.com/xml/features/report-whitespace-only-CharData | true | If enabled, CharData that consist of only whitespace characters are reported using QXmlContentHandler::characters(). If disabled, whitespace is silently discarded. |
http://trolltech.com/xml/features/report-start-end-entity | false | If enabled, the parser reports QXmlContentHandler::startEntity() and QXmlContentHandler::endEntity() events, so character data might be reported in chunks. If disabled, the parser does not report these events, but silently substitutes the entities, and reports the character data in one chunk. |
See also feature(), hasFeature(), and SAX2 Features.
Reimplemented from QXmlReader::setLexicalHandler().
See also lexicalHandler().
Reimplemented from QXmlReader::setProperty().
See also property().
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.8 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com