![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
This module is part of the Qt Enterprise Edition.
The XML module provides a well-formed XML parser using the SAX2 (Simple API for XML) interface plus an implementation of the DOM Level 2 (Document Object Model).
The Qt XML Module provides two interfaces for XML: SAX2 and DOM Level 2.
SAX is an event-based standard interface for XML parsers. The Qt interface follows the design of the SAX2 Java implementation. Its naming scheme was adapted to fit the Qt naming conventions. Details on SAX2 can be found at http://www.megginson.com/SAX/.
Support for SAX2 filters and the reader factory are under development. Furthermore the Qt implementation does not include the SAX1 compatibility classes present in the Java interface.
For an introduction to Qt's SAX2 classes see "The Qt SAX2 implementation". A code example is discussed in the "tagreader walkthrough".
DOM Level 2 is a W3C Recommendation for XML interfaces that maps the constituents of an XML document to a tree structure. Details and the specification of DOM Level 2 can be found at http://www.w3.org/DOM/. More information about the DOM classes in Qt is provided in the Qt XML DOM overview.
Qt provides the following XML related classes:
QDomAttr | Represents one attribute of a QDomElement |
QDomCDATASection | Represents an XML CDATA section |
QDomCharacterData | Represents a generic string in the DOM |
QDomComment | Represents an XML comment |
QDomDocument | The representation of an XML document |
QDomDocumentFragment | Tree of QDomNodes which is usually not a complete QDomDocument |
QDomDocumentType | The representation of the DTD in the document tree |
QDomElement | Represents one element in the DOM tree |
QDomEntity | Represents an XML entity |
QDomEntityReference | Represents an XML entity reference |
QDomImplementation | Information about the features of the DOM implementation |
QDomNamedNodeMap | Collection of nodes that can be accessed by name |
QDomNode | The base class for all nodes of the DOM tree |
QDomNodeList | List of QDomNode objects |
QDomNotation | Represents an XML notation |
QDomProcessingInstruction | Represents an XML processing instruction |
QDomText | Represents textual data in the parsed XML document |
QXmlAttributes | XML attributes |
QXmlContentHandler | Interface to report logical content of XML data |
QXmlDeclHandler | Interface to report declaration content of XML data |
QXmlDefaultHandler | Default implementation of all XML handler classes |
QXmlDTDHandler | Interface to report DTD content of XML data |
QXmlEntityResolver | Interface to resolve extern entities contained in XML data |
QXmlErrorHandler | Interface to report errors in XML data |
QXmlInputSource | The input data for the QXmlReader subclasses |
QXmlLexicalHandler | Interface to report lexical content of XML data |
QXmlLocator | The XML handler classes with information about the actual parsing position |
QXmlNamespaceSupport | Helper class for XML readers which want to include namespace support |
QXmlParseException | Used to report errors with the QXmlErrorHandler interface |
QXmlReader | Interface for XML readers (i.e. for SAX2 parsers) |
QXmlSimpleReader | Implementation of a simple XML reader (a SAX2 parser) |
Parts of the Qt XML module documentation assume that you are familiar with XML namespaces. Here we present a brief introduction; skip to "Qt XML documentation conventions" if you know this material.
Namespaces are a concept introduced into XML to allow a more modular design. With their help data processing software can easily resolve naming conflicts in XML documents.
Consider the following example:
<document> <book> <title>Practical XML</title> <author title="Ms" name="Eris Kallisti"/> <chapter> <title>A Namespace Called fnord</title> </chapter> </book> </document>
Here we find three different uses of the name title. If you wish to process this document you will encounter problems because each of the titles should be displayed in a different manner -- even though they have the same name.
The solution would be to have some means of identifying the first occurrence of title as the title of a book, i.e. to use the title element of a book namespace to distinguish it from for example the chapter title, e.g.:
<book:title>Practical XML</book:title>
book in this case is a prefix denoting the namespace.
Before we can apply a namespace to element or attribute names we must declare it.
Namespaces are URIs like http://trolltech.com/fnord/book/. This does not mean that data must be available at this address; the URI is simply used to provide a unique name.
We declare namespaces in the same way as attributes; strictly speaking they are attributes. To make for example http://trolltech.com/fnord/ the document's default XML namespace xmlns we write
xmlns="http://trolltech.com/fnord/"
To distinguish the http://trolltech.com/fnord/book/ namespace from the default, we have to supply it with a prefix:
xmlns:book="http://trolltech.com/fnord/book/"
A namespace that is declared like this can be applied to element and attribute names by prepending the appropriate prefix and a ":" delimiter. We have already seen this with the book:title element.
Element names without a prefix belong to the default namespace. This rule does not apply to attributes: an attribute without a prefix does not belong to any of the declared XML namespaces at all. Attributes always belong to the "traditional" namespace of the element in which they appear. A "traditional" namespace is not an XML namespace, it simply means that all attribute names belonging to one element must be different. Later we will see how to assign an XML namespace to an attribute.
Due to the fact that attributes without prefixes are not in any XML namespace there is no collision between the attribute title (that belongs to the author element) and for example the title element within a chapter.
Lets clarify matters with an example:
<document xmlns:book = 'http://trolltech.com/fnord/book/' xmlns = 'http://trolltech.com/fnord/' > <book> <book:title>Practical XML</book:title> <book:author xmlns:fnord = 'http://trolltech.com/fnord/' title="Ms" fnord:title="Goddess" name="Eris Kallisti"/> <chapter> <title>A Namespace Called fnord</title> </chapter> </book> </document>
Within the document element we have two namespaces declared. The default namespace http://trolltech.com/fnord/ applies to the book element, the chapter element, the appropriate title element and of course to document itself.
The book:author and book:title elements belong to the namespace with the URI http://trolltech.com/fnord/book/.
The two book:author attributes title and name have no XML namespace assigned. They are only members of the "traditional" namespace of the element book:author, meaning that for example two title attributes in book:author are forbidden.
In the above example we circumvent the last rule by adding a title attribute from the http://trolltech.com/fnord/ namespace to book:author: the fnord:title comes from the namespace with the prefix fnord that is declared in the book:author element.
Clearly the fnord namespace has the same namespace URI as the default namespace. So why didn't we simply use the default namespace we'd already declared? The answer is quite complex:
With the Qt XML classes elements and attributes can be accessed in two ways: either by refering to their qualified names consisting of the namespace prefix and the "real" name (or local name) or by the combination of local name and namespace URI.
More information on XML namespaces can be found at http://www.w3.org/TR/REC-xml-names/.
The following terms are used to distinguish the parts of names within the context of namespaces:
Elements without a ":" (like chapter in the example) do not have a namespace prefix. In this case the local part and the qualified name are identical (i.e. chapter).
Copyright © 2001 Trolltech | Trademarks | Qt version 3.0.0-beta1-beta1
|