QXmlDefaultHandler 类

QXmlDefaultHandler 类提供所有 XML 处理程序类的默认实现。 更多...

头: #include <QXmlDefaultHandler>
qmake: QT += xml
继承: QXmlContentHandler , QXmlErrorHandler , QXmlDTDHandler , QXmlEntityResolver , QXmlLexicalHandler ,和 QXmlDeclHandler

该类已过时。 提供它是为使旧源代码能继续工作。强烈建议不要在新代码中使用它。

注意: 此类的所有函数 可重入 .

公共函数

QXmlDefaultHandler ()
virtual ~QXmlDefaultHandler ()

重实现公共函数

virtual bool attributeDecl (const QString & eName , const QString & aName , const QString & type , const QString & valueDefault , const QString & value ) override
virtual bool characters (const QString & ch ) override
virtual bool comment (const QString & ch ) override
virtual bool endCDATA () override
virtual bool endDTD () override
virtual bool endDocument () override
virtual bool endElement (const QString & namespaceURI , const QString & localName , const QString & qName ) override
virtual bool endEntity (const QString & name ) override
virtual bool endPrefixMapping (const QString & prefix ) override
virtual bool error (const QXmlParseException & exception ) override
virtual QString errorString () const override
virtual bool externalEntityDecl (const QString & name , const QString & publicId , const QString & systemId ) override
virtual bool fatalError (const QXmlParseException & exception ) override
virtual bool ignorableWhitespace (const QString & ch ) override
virtual bool internalEntityDecl (const QString & name , const QString & value ) override
virtual bool notationDecl (const QString & name , const QString & publicId , const QString & systemId ) override
virtual bool processingInstruction (const QString & target , const QString & data ) override
virtual bool resolveEntity (const QString & publicId , const QString & systemId , QXmlInputSource *& ret ) override
virtual void setDocumentLocator (QXmlLocator * locator ) override
virtual bool skippedEntity (const QString & name ) override
virtual bool startCDATA () override
virtual bool startDTD (const QString & name , const QString & publicId , const QString & systemId ) override
virtual bool startDocument () override
virtual bool startElement (const QString & namespaceURI , const QString & localName , const QString & qName , const QXmlAttributes & atts ) override
virtual bool startEntity (const QString & name ) override
virtual bool startPrefixMapping (const QString & prefix , const QString & uri ) override
virtual bool unparsedEntityDecl (const QString & name , const QString & publicId , const QString & systemId , const QString & notationName ) override
virtual bool warning (const QXmlParseException & exception ) override

详细描述

This class gathers together the features of the specialized handler classes, making it a convenient starting point when implementing custom handlers for subclasses of QXmlReader , particularly QXmlSimpleReader . The virtual functions from each of the base classes are reimplemented in this class, providing sensible default behavior for many common cases. By subclassing this class, and overriding these functions, you can concentrate on implementing the parts of the handler relevant to your application.

The XML reader must be told which handler to use for different kinds of events during parsing. This means that, although QXmlDefaultHandler provides default implementations of functions inherited from all its base classes, we can still use specialized handlers for particular kinds of events.

For example, QXmlDefaultHandler subclasses both QXmlContentHandler and QXmlErrorHandler , so by subclassing it we can use the same handler for both of the following reader functions:

    xmlReader.setContentHandler(handler);
    xmlReader.setErrorHandler(handler);
					

Since the reader will inform the handler of parsing errors, it is necessary to reimplement QXmlErrorHandler::fatalError () if, for example, we want to stop parsing when such an error occurs:

bool Handler::fatalError (const QXmlParseException & exception)
{
    qWarning() << "Fatal error on line" << exception.lineNumber()
               << ", column" << exception.columnNumber() << ':'
               << exception.message();
    return false;
}
					

The above function returns false , which tells the reader to stop parsing. To continue to use the same reader, it is necessary to create a new handler instance, and set up the reader to use it in the manner described above.

It is useful to examine some of the functions inherited by QXmlDefaultHandler, and consider why they might be reimplemented in a custom handler. Custom handlers will typically reimplement QXmlContentHandler::startDocument () to prepare the handler for new content. Document elements and the text within them can be processed by reimplementing QXmlContentHandler::startElement (), QXmlContentHandler::endElement (),和 QXmlContentHandler::characters (). You may want to reimplement QXmlContentHandler::endDocument () to perform some finalization or validation on the content once the document has been read completely.

另请参阅 QXmlDTDHandler , QXmlDeclHandler , QXmlContentHandler , QXmlEntityResolver , QXmlErrorHandler , QXmlLexicalHandler , and Introduction to SAX2.

成员函数文档编制

QXmlDefaultHandler:: QXmlDefaultHandler ()

Constructs a handler for use with subclasses of QXmlReader.

[virtual] QXmlDefaultHandler:: ~QXmlDefaultHandler ()

Destroys the handler.

[override virtual] bool QXmlDefaultHandler:: attributeDecl (const QString & eName , const QString & aName , const QString & type , const QString & valueDefault , const QString & value )

重实现: QXmlDeclHandler::attributeDecl (const QString &eName, const QString &aName, const QString &type, const QString &valueDefault, const QString &value).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: characters (const QString & ch )

重实现: QXmlContentHandler::characters (const QString &ch).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: comment (const QString & ch )

重实现: QXmlLexicalHandler::comment (const QString &ch).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: endCDATA ()

重实现: QXmlLexicalHandler::endCDATA ().

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: endDTD ()

重实现: QXmlLexicalHandler::endDTD ().

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: endDocument ()

重实现: QXmlContentHandler::endDocument ().

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: endElement (const QString & namespaceURI , const QString & localName , const QString & qName )

重实现: QXmlContentHandler::endElement (const QString &namespaceURI, const QString &localName, const QString &qName).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: endEntity (const QString & name )

重实现: QXmlLexicalHandler::endEntity (const QString &name).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: endPrefixMapping (const QString & prefix )

重实现: QXmlContentHandler::endPrefixMapping (const QString &prefix).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: error (const QXmlParseException & exception )

重实现: QXmlErrorHandler::error (const QXmlParseException &exception).

This reimplementation does nothing.

[override virtual] QString QXmlDefaultHandler:: errorString () const

重实现: QXmlContentHandler::errorString () const.

Returns the default error string.

[override virtual] bool QXmlDefaultHandler:: externalEntityDecl (const QString & name , const QString & publicId , const QString & systemId )

重实现: QXmlDeclHandler::externalEntityDecl (const QString &name, const QString &publicId, const QString &systemId).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: fatalError (const QXmlParseException & exception )

重实现: QXmlErrorHandler::fatalError (const QXmlParseException &exception).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: ignorableWhitespace (const QString & ch )

重实现: QXmlContentHandler::ignorableWhitespace (const QString &ch).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: internalEntityDecl (const QString & name , const QString & value )

重实现: QXmlDeclHandler::internalEntityDecl (const QString &name, const QString &value).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: notationDecl (const QString & name , const QString & publicId , const QString & systemId )

重实现: QXmlDTDHandler::notationDecl (const QString &name, const QString &publicId, const QString &systemId).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: processingInstruction (const QString & target , const QString & data )

重实现: QXmlContentHandler::processingInstruction (const QString &target, const QString &data).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: resolveEntity (const QString & publicId , const QString & systemId , QXmlInputSource *& ret )

重实现: QXmlEntityResolver::resolveEntity (const QString &publicId, const QString &systemId, QXmlInputSource *&ret).

设置 ret to nullptr , so that the reader uses the system identifier provided in the XML document.

[override virtual] void QXmlDefaultHandler:: setDocumentLocator ( QXmlLocator * locator )

重实现: QXmlContentHandler::setDocumentLocator (QXmlLocator *locator).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: skippedEntity (const QString & name )

重实现: QXmlContentHandler::skippedEntity (const QString &name).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: startCDATA ()

重实现: QXmlLexicalHandler::startCDATA ().

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: startDTD (const QString & name , const QString & publicId , const QString & systemId )

重实现: QXmlLexicalHandler::startDTD (const QString &name, const QString &publicId, const QString &systemId).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: startDocument ()

重实现: QXmlContentHandler::startDocument ().

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: startElement (const QString & namespaceURI , const QString & localName , const QString & qName , const QXmlAttributes & atts )

重实现: QXmlContentHandler::startElement (const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: startEntity (const QString & name )

重实现: QXmlLexicalHandler::startEntity (const QString &name).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: startPrefixMapping (const QString & prefix , const QString & uri )

重实现: QXmlContentHandler::startPrefixMapping (const QString &prefix, const QString &uri).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: unparsedEntityDecl (const QString & name , const QString & publicId , const QString & systemId , const QString & notationName )

重实现: QXmlDTDHandler::unparsedEntityDecl (const QString &name, const QString &publicId, const QString &systemId, const QString ¬ationName).

This reimplementation does nothing.

[override virtual] bool QXmlDefaultHandler:: warning (const QXmlParseException & exception )

重实现: QXmlErrorHandler::warning (const QXmlParseException &exception).

This reimplementation does nothing.