返回介绍

QXmlContentHandler Class

发布于 2019-10-04 15:04:15 字数 10722 浏览 985 评论 0 收藏 0

The QXmlContentHandler class provides an interface to report the logical content of XML data. More...

#include <qxml.h>

Inherited by QXmlDefaultHandler.

List of all member functions.

Public Members

  • virtual void setDocumentLocator ( QXmlLocator*locator ) = 0
  • virtual bool startDocument () = 0
  • virtual bool endDocument () = 0
  • virtual bool startPrefixMapping ( constQString&prefix, constQString&uri ) = 0
  • virtual bool endPrefixMapping ( constQString&prefix ) = 0
  • virtual bool startElement ( constQString&namespaceURI, constQString&localName, constQString&qName, constQXmlAttributes&atts ) = 0
  • virtual bool endElement ( constQString&namespaceURI, constQString&localName, constQString&qName ) = 0
  • virtual bool characters ( constQString&ch ) = 0
  • virtual bool ignorableWhitespace ( constQString&ch ) = 0
  • virtual bool processingInstruction ( constQString&target, constQString&data ) = 0
  • virtual bool skippedEntity ( constQString&name ) = 0
  • virtual QString errorString () = 0

Detailed Description

The QXmlContentHandler class provides an interface to report the logical content of XML data.

If the application needs to be informed of basic parsing events, it implements this interface and sets it with QXmlReader::setContentHandler(). The reader reports basic document-related events like the start and end of elements and character data through this interface.

The order of events in this interface is very important, and mirrors the order of information in the document itself. For example, all of an element's content (character data, processing instructions, and/or sub-elements) appears, in order, between the startElement() event and the corresponding endElement() event.

The class QXmlDefaultHandler provides a default implementation for this interface; subclassing from the QXmlDefaultHandler class is very convenient if you only want to be informed of some parsing events.

The startDocument() function is called at the start of the document, and endDocument() is called at the end. Before parsing begins setDocumentLocator() is called. For each element startElement() is called, with endElement() being called at the end of each element. The characters() function is called with chunks of character data; ignorableWhitespace() is called with chunks of whitespace and processingInstruction() is called with processing instructions. If an entity is skipped skippedEntity() is called. At the beginning of prefix-URI scopes startPrefixMapping() is called.

See also the Introduction to SAX2.

See also QXmlDTDHandler, QXmlDeclHandler, QXmlEntityResolver, QXmlErrorHandler, QXmlLexicalHandler and XML.


Member Function Documentation

bool QXmlContentHandler::characters ( constQString&ch ) [pure virtual]

The reader calls this function when it has parsed a chunk of character data (either normal character data or character data inside a CDATA section; if you have to distinguish between those two types you must use QXmlLexicalHandler::startCDATA() and QXmlLexicalHandler::endCDATA()). The character data is reported in ch.

Some readers report whitespace in element content using the ignorableWhitespace() function rather than using this one.

A reader may report the character data of an element in more than one chunk; e.g. a reader might want to report "a<b" in three characters() events ("a ", "<" and " b").

If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.

bool QXmlContentHandler::endDocument () [pure virtual]

The reader calls this function after it has finished parsing. It is called just once, and is the last handler function called. It is called after the reader has read all input or has abandoned parsing because of a fatal error.

If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.

See also startDocument().

bool QXmlContentHandler::endElement ( constQString&namespaceURI, constQString&localName, constQString&qName ) [pure virtual]

The reader calls this function when it has parsed an end element tag with the qualified name qName, the local name localName and the namespace URI namespaceURI.

If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.

See also the namespace description.

See also startElement().

Example: xml/tagreader/structureparser.cpp.

bool QXmlContentHandler::endPrefixMapping ( constQString&prefix ) [pure virtual]

The reader calls this function to signal the end of a prefix mapping for the prefix prefix.

If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.

See also the namespace description.

See also startPrefixMapping().

QString QXmlContentHandler::errorString () [pure virtual]

The reader calls this function to get an error string, e.g. if any of the handler functions returns FALSE.

bool QXmlContentHandler::ignorableWhitespace ( constQString&ch ) [pure virtual]

Some readers may use this function to report each chunk of whitespace in element content. The whitespace reported in ch.

If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.

bool QXmlContentHandler::processingInstruction ( constQString&target, constQString&data ) [pure virtual]

The reader calls this function when it has parsed a processing instruction.

target is the target name of the processing instruction and data is the data in the processing instruction.

If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.

void QXmlContentHandler::setDocumentLocator ( QXmlLocator*locator ) [pure virtual]

The reader calls this function before it starts parsing the document. The argument locator is a pointer to a QXmlLocator which allows the application to get the parsing position within the document.

Do not destroy the locator; it is destroyed when the reader is destroyed (do not use the locator after the reader is destroyed).

bool QXmlContentHandler::skippedEntity ( constQString&name ) [pure virtual]

Some readers may skip entities if they have not seen the declarations (e.g. because they are in an external DTD). If they do so they report that they skipped the entity called name by calling this function.

If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.

bool QXmlContentHandler::startDocument () [pure virtual]

The reader calls this function when it starts parsing the document. The reader calls this function just once, after the call to setDocumentLocator(), and before any other functions in this class or in the QXmlDTDHandler class are called.

If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.

See also endDocument().

Example: xml/tagreader/structureparser.cpp.

bool QXmlContentHandler::startElement ( constQString&namespaceURI, constQString&localName, constQString&qName, constQXmlAttributes&atts ) [pure virtual]

The reader calls this function when it has parsed a start element tag.

There is a corresponding endElement() call when the corresponding end element tag is read. The startElement() and endElement() calls are always nested correctly. Empty element tags (e.g. <x/>) cause a startElement() call immediately followed by an endElement() call.

The attribute list provided contains only attributes with explicit values. The attribute list contains attributes used for namespace declaration (i.e. attributes starting with xmlns) only if the namespace-prefix property of the reader is TRUE.

The argument namespaceURI is the namespace URI, or a null string if the element has no namespace URI or if no namespace processing is done. localName is the local name (without prefix), or a null string if no namespace processing is done, qName is the qualified name (with prefix) and atts are the attributes attached to the element. If there are no attributes, atts is an empty attributes object.

If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.

See also the namespace description.

See also endElement().

Example: xml/tagreader/structureparser.cpp.

bool QXmlContentHandler::startPrefixMapping ( constQString&prefix, constQString&uri ) [pure virtual]

The reader calls this function to signal the begin of a prefix-URI namespace mapping scope. This information is not necessary for normal namespace processing since the reader automatically replaces prefixes for element and attribute names.

Note that startPrefixMapping() and endPrefixMapping() calls are not guaranteed to be properly nested relative to each other: all startPrefixMapping() events occur before the corresponding startElement() event, and all endPrefixMapping() events occur after the corresponding endElement() event, but their order is not otherwise guaranteed.

The argument prefix is the namespace prefix being declared and the argument uri is the namespace URI the prefix is mapped to.

If this function returns FALSE the reader stops parsing and reports an error. The reader uses the function errorString() to get the error message.

See also the namespace description.

See also endPrefixMapping().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文