Classes - Annotated - Tree - Functions - Home - Structure

QXmlContentHandler Class Reference
[XML module]

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

#include <qxml.h>

Inherited by QXmlDefaultHandler.

List of all member functions.

Public Members


Detailed Description

The QXmlContentHandler class provides an interface to report 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 subelements) appear, in order, between the startElement() event and the corresponding endElement() event.

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

See also the Introduction to SAX2.

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


Member Function Documentation

bool QXmlContentHandler::characters ( const QString & ch ) [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 have to use QXmlLexicalHandler::startCDATA() and QXmlLexicalHandler::endCDATA() in addition). The character data is reported in ch.

Some readers report whitespace in element content using the ignorableWhitespace() function rather than this one (QXmlSimpleReader does not do it, though).

A reader is allowed to report the character data of an element in more than one chunk; e.g. a reader might want to report "a &lt; 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 that is used for reporting the error.

bool QXmlContentHandler::endDocument () [virtual]

The reader calls this function after it has finished the parsing. It is only called once. It is the last function of all handler functions that is 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 that is used for reporting the error.

See also startDocument().

bool QXmlContentHandler::endElement ( const QString & namespaceURI, const QString & localName, const QString & qName ) [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 that is used for reporting the error.

See also the namespace description.

See also startElement().

Examples: xml/tagreader-with-features/structureparser.cpp and xml/tagreader/structureparser.cpp.

bool QXmlContentHandler::endPrefixMapping ( const QString & prefix ) [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 that is used for reporting the error.

See also the namespace description.

See also startPrefixMapping().

QString QXmlContentHandler::errorString () [virtual]

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

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

Some readers may use this function to report each chunk of whitespace in element content (QXmlSimpleReader does not though). 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 that is used for reporting the error.

bool QXmlContentHandler::processingInstruction ( const QString & target, const QString & data ) [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 of 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 that is used for reporting the error.

void QXmlContentHandler::setDocumentLocator ( QXmlLocator * locator ) [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 actual position of the parsing in the document.

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

bool QXmlContentHandler::skippedEntity ( const QString & name ) [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 with the name 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 that is used for reporting the error.

bool QXmlContentHandler::startDocument () [virtual]

The reader calls this function when it starts parsing the document. The reader calls this function only once before any other functions in this class or in the QXmlDTDHandler class are called (except QXmlContentHandler::setDocumentLocator()).

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

See also endDocument().

Example: xml/tagreader/structureparser.cpp.

bool QXmlContentHandler::startElement ( const QString & namespaceURI, const QString & localName, const QString & qName, const QXmlAttributes & atts ) [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 was read. The startElement() and endElement() calls are always nested correctly. Empty element tags (e.g. <a/>) are reported by startElement() directly followed by a call to endElement().

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 that is used for reporting the error.

See also the namespace description.

See also endElement().

Examples: xml/tagreader-with-features/structureparser.cpp and xml/tagreader/structureparser.cpp.

bool QXmlContentHandler::startPrefixMapping ( const QString & prefix, const QString & uri ) [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 that is used for reporting the error.

See also the namespace description.

See also endPrefixMapping().


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.


Copyright © 2001 TrolltechTrademarks
Qt version 3.0.0-beta1-beta1