Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QXmlStreamReader Class Reference

Inheritance diagram for QXmlStreamReader:

XbelReader XbelReader

List of all members.


Detailed Description

The QXmlStreamReader class provides a fast well-formed XML parser with a simple streaming API.

Since:
4.3

The basic concept of a stream reader is to report an XML document as a stream of tokens, similar to SAX. The main difference between QXmlStreamReader and SAX is how these XML tokens are reported. With SAX, the application must provide handlers that receive so-called XML events from the parser at the parser's convenience. With QXmlStreamReader, the application code itself drives the loop and pulls tokens from the reader one after another as it needs them. This is done by calling readNext(), which makes the reader read from the input stream until it has completed a new token, and then returns its tokenType(). A set of convenient functions like isStartElement() or text() then allows to examine this token, and to obtain information about what has been read. The big advantage of the pulling approach is the possibility to build recursive descent parsers, meaning you can split your XML parsing code easily into different methods or classes. This makes it easy to keep track of the application's own state when parsing XML.

A typical loop with QXmlStreamReader looks like this:

doc/src/snippets/code/src.corelib.xml.qxmlstream.cpp 0

QXmlStreamReader is a well-formed XML 1.0 parser that does not include external parsed entities. As long as no error occurs, the application code can thus be assured that the data provided by the stream reader satisfies the W3C's criteria for well-formed XML. For example, you can be certain that all tags are indeed nested and closed properly, that references to internal entities have been replaced with the correct replacement text, and that attributes have been normalized or added according to the internal subset of the DTD.

If an error does occur while parsing, atEnd() returns true and error() returns the kind of error that occurred. hasError() can also be used to check whether an error has occurred. The functions errorString(), lineNumber(), columnNumber(), and characterOffset() make it possible to generate a verbose human-understandable error or warning message. In order to simplify application code, QXmlStreamReader contains a raiseError() mechanism that makes it possible to raise custom errors that then trigger the same error handling code path.

The {QXmlStream Bookmarks Example} illustrates how to use the recursive descent technique with a subclassed stream reader to read an XML bookmark file (XBEL).

Definition at line 273 of file qxmlstream.h.


Public Types

enum  Error {
  NoError, UnexpectedElementError, CustomError, NotWellFormedError,
  PrematureEndOfDocumentError
}
enum  TokenType {
  NoToken = 0, Invalid, StartDocument, EndDocument,
  StartElement, EndElement, Characters, Comment,
  DTD, EntityReference, ProcessingInstruction
}

Public Member Functions

void addData (const char *data)
void addData (const QString &data)
void addData (const QByteArray &data)
void addExtraNamespaceDeclaration (const QXmlStreamNamespaceDeclaration &extraNamespaceDeclaraction)
void addExtraNamespaceDeclarations (const QXmlStreamNamespaceDeclarations &extraNamespaceDeclaractions)
bool atEnd () const
QXmlStreamAttributes attributes () const
qint64 characterOffset () const
void clear ()
qint64 columnNumber () const
QIODevicedevice () const
QStringRef documentEncoding () const
QStringRef documentVersion () const
QStringRef dtdName () const
QStringRef dtdPublicId () const
QStringRef dtdSystemId () const
QXmlStreamEntityDeclarations entityDeclarations () const
QXmlStreamEntityResolverentityResolver () const
Error error () const
QString errorString () const
bool hasError () const
bool isCDATA () const
bool isCharacters () const
bool isComment () const
bool isDTD () const
bool isEndDocument () const
bool isEndElement () const
bool isEntityReference () const
bool isProcessingInstruction () const
bool isStandaloneDocument () const
bool isStartDocument () const
bool isStartElement () const
bool isWhitespace () const
qint64 lineNumber () const
QStringRef name () const
QXmlStreamNamespaceDeclarations namespaceDeclarations () const
bool namespaceProcessing () const
QStringRef namespaceUri () const
QXmlStreamNotationDeclarations notationDeclarations () const
QStringRef prefix () const
QStringRef processingInstructionData () const
QStringRef processingInstructionTarget () const
QStringRef qualifiedName () const
 QXmlStreamReader (const char *data)
 QXmlStreamReader (const QString &data)
 QXmlStreamReader (const QByteArray &data)
 QXmlStreamReader (QIODevice *device)
 QXmlStreamReader ()
void raiseError (const QString &message=QString())
QString readElementText ()
TokenType readNext ()
void setDevice (QIODevice *device)
void setEntityResolver (QXmlStreamEntityResolver *resolver)
void setNamespaceProcessing (bool)
QStringRef text () const
QString tokenString () const
TokenType tokenType () const
 ~QXmlStreamReader ()

Private Attributes

QXmlStreamReaderPrivate * d_ptr

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index