Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QXmlSimpleReader Class

TheQXmlSimpleReader class provides an implementation of a simple XML parser.More...

Header:#include <QXmlSimpleReader>
Inherits:QXmlReader

Warning: This class is notreentrant.

Public Functions

QXmlSimpleReader()
virtual~QXmlSimpleReader()
virtual boolparse(const QXmlInputSource * input, bool incremental)
virtual boolparseContinue()

Reimplemented Public Functions

virtual QXmlDTDHandler *DTDHandler() const
virtual QXmlContentHandler *contentHandler() const
virtual QXmlDeclHandler *declHandler() const
virtual QXmlEntityResolver *entityResolver() const
virtual QXmlErrorHandler *errorHandler() const
virtual boolfeature(const QString & name, bool * ok = 0) const
virtual boolhasFeature(const QString & name) const
virtual boolhasProperty(const QString & name) const
virtual QXmlLexicalHandler *lexicalHandler() const
virtual boolparse(const QXmlInputSource & input)
virtual boolparse(const QXmlInputSource * input)
virtual void *property(const QString & name, bool * ok = 0) const
virtual voidsetContentHandler(QXmlContentHandler * handler)
virtual voidsetDTDHandler(QXmlDTDHandler * handler)
virtual voidsetDeclHandler(QXmlDeclHandler * handler)
virtual voidsetEntityResolver(QXmlEntityResolver * handler)
virtual voidsetErrorHandler(QXmlErrorHandler * handler)
virtual voidsetFeature(const QString & name, bool enable)
virtual voidsetLexicalHandler(QXmlLexicalHandler * handler)
virtual voidsetProperty(const QString & name, void * value)

Detailed Description

TheQXmlSimpleReader 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 aQFile to supply the input. Here, we create a reader, and define an input source to be used by the reader:

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 subclassingQXmlDefaultHandler, 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 theparse() 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 tellingparse() to work incrementally, and making subsequent calls to theparseContinue() function, until all the data has been processed.

A common way to perform incremental parsing is to connect thereadyRead() signal of anetwork reply a slot, and handle the incoming data there. SeeQNetworkAccessManager.

Aspects of the parsing behavior can be adapted usingsetFeature() andsetProperty().

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 usingQXmlSimpleReader with a locking mechanism, such as aQMutex.

Member Function Documentation

QXmlSimpleReader::QXmlSimpleReader()

Constructs a simple XML reader.

[virtual]QXmlSimpleReader::~QXmlSimpleReader()

Destroys the simple XML reader.

[virtual]QXmlDTDHandler * QXmlSimpleReader::DTDHandler() const

Reimplemented fromQXmlReader::DTDHandler().

See alsosetDTDHandler().

[virtual]QXmlContentHandler * QXmlSimpleReader::contentHandler() const

Reimplemented fromQXmlReader::contentHandler().

See alsosetContentHandler().

[virtual]QXmlDeclHandler * QXmlSimpleReader::declHandler() const

Reimplemented fromQXmlReader::declHandler().

See alsosetDeclHandler().

[virtual]QXmlEntityResolver * QXmlSimpleReader::entityResolver() const

Reimplemented fromQXmlReader::entityResolver().

See alsosetEntityResolver().

[virtual]QXmlErrorHandler * QXmlSimpleReader::errorHandler() const

Reimplemented fromQXmlReader::errorHandler().

See alsosetErrorHandler().

[virtual]bool QXmlSimpleReader::feature(constQString & name,bool * ok = 0) const

Reimplemented fromQXmlReader::feature().

See alsosetFeature().

[virtual]bool QXmlSimpleReader::hasFeature(constQString & name) const

Reimplemented fromQXmlReader::hasFeature().

[virtual]bool QXmlSimpleReader::hasProperty(constQString & name) const

Reimplemented fromQXmlReader::hasProperty().

[virtual]QXmlLexicalHandler * QXmlSimpleReader::lexicalHandler() const

Reimplemented fromQXmlReader::lexicalHandler().

See alsosetLexicalHandler().

[virtual]bool QXmlSimpleReader::parse(constQXmlInputSource & input)

Reimplemented fromQXmlReader::parse().

[virtual]bool QXmlSimpleReader::parse(constQXmlInputSource * input)

Reimplemented fromQXmlReader::parse().

Reads an XML document frominput and parses it in one pass (non-incrementally). Returns true if the parsing was successful; otherwise returns false.

[virtual]bool QXmlSimpleReader::parse(constQXmlInputSource * input,bool incremental)

Reads an XML document frominput and parses it. Returns true if the parsing is completed successfully; otherwise returns false, indicating that an error occurred.

Ifincremental is false, this function will return false if the XML file is not read completely. The parsing cannot be continued in this case.

Ifincremental is true, the parser does not return false if it reaches the end of theinput before reaching the end of the XML file. Instead, it stores the state of the parser so that parsing can be continued later when more data is available. In such a case, you can use the functionparseContinue() to continue with parsing. This class stores a pointer to the input sourceinput and theparseContinue() function tries to read from that input source. Therefore, you should not delete the input sourceinput until you no longer need to callparseContinue().

If this function is called withincremental set to true while an incremental parse is in progress, a new parsing session will be started, and the previous session will be lost.

See alsoparseContinue() andQTcpSocket.

[virtual]bool QXmlSimpleReader::parseContinue()

Continues incremental parsing, taking input from theQXmlInputSource that was specified with the most recent call toparse(). To use this function, youmust have calledparse() with the incremental argument set to true.

Returns false if a parsing error occurs; otherwise returns true, even if the end of the XML file has not been reached. You can continue parsing at a later stage by calling this function again when there is more data available to parse.

Calling this function when there is no data available in the input source indicates to the reader that the end of the XML file has been reached. If the input supplied up to this point was not well-formed then a parsing error occurs, and false is returned. If the input supplied was well-formed, true is returned. It is important to end the input in this way because it allows you to reuse the reader to parse other XML files.

Calling this function after the end of file has been reached, but without available data will cause false to be returned whether the previous input was well-formed or not.

See alsoparse(),QXmlInputSource::data(), andQXmlInputSource::next().

[virtual]void * QXmlSimpleReader::property(constQString & name,bool * ok = 0) const

Reimplemented fromQXmlReader::property().

See alsosetProperty().

[virtual]void QXmlSimpleReader::setContentHandler(QXmlContentHandler * handler)

Reimplemented fromQXmlReader::setContentHandler().

See alsocontentHandler().

[virtual]void QXmlSimpleReader::setDTDHandler(QXmlDTDHandler * handler)

Reimplemented fromQXmlReader::setDTDHandler().

[virtual]void QXmlSimpleReader::setDeclHandler(QXmlDeclHandler * handler)

Reimplemented fromQXmlReader::setDeclHandler().

See alsodeclHandler().

[virtual]void QXmlSimpleReader::setEntityResolver(QXmlEntityResolver * handler)

Reimplemented fromQXmlReader::setEntityResolver().

See alsoentityResolver().

[virtual]void QXmlSimpleReader::setErrorHandler(QXmlErrorHandler * handler)

Reimplemented fromQXmlReader::setErrorHandler().

See alsoerrorHandler().

[virtual]void QXmlSimpleReader::setFeature(constQString & name,bool enable)

Reimplemented fromQXmlReader::setFeature().

Turns on the featurename ifenable is true; otherwise turns it off.

Thename parameter must be one of the following strings:

FeatureDefaultNotes
http://xml.org/sax/features/namespacestrueIf enabled, namespaces are reported to the content handler.
http://xml.org/sax/features/namespace-prefixesfalseIf enabled, the original prefixed names and attributes used for namespace declarations are reported.
http://trolltech.com/xml/features/report-whitespace-only-CharDatatrueIf enabled, CharData that consist of only whitespace characters are reported usingQXmlContentHandler::characters(). If disabled, whitespace is silently discarded.
http://trolltech.com/xml/features/report-start-end-entityfalseIf 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 alsofeature(),hasFeature(), andSAX2 Features.

[virtual]void QXmlSimpleReader::setLexicalHandler(QXmlLexicalHandler * handler)

Reimplemented fromQXmlReader::setLexicalHandler().

See alsolexicalHandler().

[virtual]void QXmlSimpleReader::setProperty(constQString & name,void * value)

Reimplemented fromQXmlReader::setProperty().

See alsoproperty().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp