~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qtxml.html

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-11-02 18:30:08 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (15.2.5 experimental)
  • mto: This revision was merged to the branch mainline in revision 88.
  • Revision ID: james.westby@ubuntu.com-20091102183008-b6a4gcs128mvfb3m
Tags: upstream-4.6.0~beta1
ImportĀ upstreamĀ versionĀ 4.6.0~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
<!DOCTYPE html
3
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
 
<!-- /fasttmp/mkdist-qt-4.5.2-1245473805/qt-x11-opensource-src-4.5.2/doc/src/qtxml.qdoc -->
 
5
<!-- modules.qdoc -->
6
6
<head>
7
 
  <title>Qt 4.5: QtXml Module</title>
 
7
  <title>Qt 4.6: QtXml Module</title>
8
8
  <link rel="prev" href="qtsvg.html" />
9
9
  <link rel="contents" href="modules.html" />
10
10
  <link rel="next" href="qtxmlpatterns.html" />
13
13
<body>
14
14
<table border="0" cellpadding="0" cellspacing="0" width="100%">
15
15
<tr>
16
 
<td align="left" valign="top" width="32"><a href="http://qtsoftware.com/products/qt"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
17
 
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="namespaces.html"><font color="#004faf">All&nbsp;Namespaces</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
18
 
<td align="right" valign="top" width="230"></td></tr></table><p>
 
16
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
 
17
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td><td class="searchBar" align="right" valign="center"><form action="http://www.google.com/cse" id="cse-search-box"><div><input type="hidden" name="cx" value="000136343326384750312:dhbxnqlakyu" /><input type="hidden" name="ie" value="UTF-8" /><input type="text" name="q" size="31" /><input type="submit" name="sa" value="Search" /></div></form></td>
 
18
</tr></table><p>
19
19
[Previous: <a href="qtsvg.html">QtSvg Module</a>]
20
 
[<a href="modules.html">Qt's Modules</a>]
 
20
[<a href="modules.html">All Qt Modules</a>]
21
21
[Next: <a href="qtxmlpatterns.html">QtXmlPatterns Module</a>]
22
22
</p>
23
23
<h1 class="title">QtXml Module<br /><span class="subtitle"></span>
60
60
</table></p>
61
61
<a name="details"></a>
62
62
<h2>Detailed Description</h2>
63
 
<p>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 <a href="http://www.saxproject.org">http://www.saxproject.org</a>.</p>
64
 
<p>Support for SAX2 filters and the reader factory are under development. The Qt implementation does not include the SAX1 compatibility classes present in the Java interface. For an introduction to Qt's SAX2 classes, see <a href="#the-qt-sax2-classes">The Qt SAX2 Classes</a>.</p>
65
 
<p>DOM Level 2 is a W3C Recommendation for XML interfaces that maps the constituents of an XML document to a tree structure. The specification of DOM Level 2 can be found at <a href="http://www.w3.org/DOM/">http://www.w3.org/DOM/</a>. For more information about the DOM classes in Qt is provided, see <a href="#the-qt-dom-classes">The Qt DOM Classes</a>.</p>
66
 
<p>Since version 4.3, Qt provides two new classes for reading and writing XML: <a href="qxmlstreamreader.html">QXmlStreamReader</a> and <a href="qxmlstreamwriter.html">QXmlStreamWriter</a>.</p>
67
 
<p>In addition to core XML support, classes for higher level querying and manipulation of XML data, are provided by the <a href="qtxmlpatterns.html">QtXmlPatterns</a> module. In the <a href="qtsvg.html">QtSvg</a> module, the <a href="qsvgrenderer.html">QSvgRenderer</a> and <a href="qsvggenerator.html">QSvgGenerator</a> classes can read and write a subset of SVG, an XML-based file format. Qt also provides helper functions that may be useful to those working with XML and XHTML: see <a href="qt.html#escape">Qt::escape</a>() and <a href="qt.html#convertFromPlainText">Qt::convertFromPlainText</a>().</p>
68
 
<p>Further XML support is provided by the <a href="http://www.qtsoftware.com/products/add-on-products">Qt Solutions</a> group who provide, for example, classes that support SOAP and MML with the Qt XML classes.</p>
69
 
<p>This module is part of the <a href="commercialeditions.html#qt-full-framework-edition">Qt Full Framework Edition</a> and the <a href="opensourceedition.html">Open Source Versions of Qt</a>.</p>
70
 
<p>Topics:</p>
71
 
<ul><li><a href="#configuring-the-build-process">Configuring the Build Process</a></li>
72
 
<li><a href="#the-qtxml-stream-classes">The QtXml Stream Classes</a></li>
73
 
<li><a href="#the-qt-sax2-classes">The Qt SAX2 Classes</a></li>
74
 
<ul><li><a href="#introduction-to-sax2">Introduction to SAX2</a></li>
75
 
<li><a href="#sax2-features">SAX2 Features</a></li>
76
 
<li><a href="#namespace-support-via-features">Namespace Support via Features</a></li>
77
 
<ul><li><a href="#summary">Summary</a></li>
78
 
</ul>
79
 
<li><a href="#properties">Properties</a></li>
80
 
</ul>
81
 
<li><a href="#the-qt-dom-classes">The Qt DOM Classes</a></li>
82
 
<ul><li><a href="#introduction-to-dom">Introduction to DOM</a></li>
83
 
</ul>
84
 
<li><a href="#an-introduction-to-namespaces">An Introduction to Namespaces</a></li>
85
 
<ul><li><a href="#conventions-used-in-the-qt-xml-documentation">Conventions Used in the Qt XML Documentation</a></li>
86
 
</ul>
87
 
</ul>
88
 
<a name="configuring-the-build-process"></a>
89
 
<h3>Configuring the Build Process</h3>
90
 
<p>Applications that use Qt's XML classes need to be configured to be built against the QtXml module. The following declaration in a <tt>qmake</tt> project file ensures that an application is compiled and linked appropriately:</p>
91
63
<p>To include the definitions of the module's classes, use the following directive:</p>
92
64
<pre> #include &lt;QtXml&gt;</pre>
93
65
<p>To link against the module, add this line to your <a href="qmake-manual.html#qmake">qmake</a> <tt>.pro</tt> file:</p>
94
66
<pre> QT += xml</pre>
95
 
<p>This line is necessary because only the <a href="qtcore.html">QtCore</a> and <a href="qtgui.html">QtGui</a> modules are used in the default build process.</p>
96
 
<a name="the-qtxml-stream-classes"></a>
97
 
<h3>The QtXml Stream Classes</h3>
98
 
<p>The <a href="qxmlstreamreader.html">QXmlStreamReader</a> and <a href="qxmlstreamwriter.html">QXmlStreamWriter</a> are two new classes provided in Qt 4.3 and later. A stream reader reports an XML document as a stream of tokens. This differs from SAX as SAX applications provide handlers to receive XML events from the parser whereas the <a href="qxmlstreamreader.html">QXmlStreamReader</a> drives the loop, pulling tokens from the reader when they are needed. This pulling approach makes it possible to build recursive descent parsers, allowing XML parsing code to be split into different methods or classes.</p>
99
 
<p><a href="qxmlstreamreader.html">QXmlStreamReader</a> is a well-formed XML 1.0 parser that excludes external parsed entities. Hence, data provided by the stream reader adheres to the W3C's criteria for well-formed XML, as long as no error occurs. Otherwise, functions such as <a href="qxmlstreamreader.html#atEnd">atEnd()</a>, <a href="qxmlstreamreader.html#error">error()</a> and <a href="qxmlstreamreader.html#hasError">hasError()</a> can be used to check and view the errors.</p>
100
 
<p>An example of <a href="qxmlstreamreader.html">QXmlStreamReader</a> implementation would be the <tt>XbelReader</tt> in <a href="xml-streambookmarks.html">QXmlStream Bookmarks Example</a>, which is a subclass of <a href="qxmlstreamreader.html">QXmlStreamReader</a>. The constructor takes <i>treeWidget</i> as a parameter and the class has Xbel specific functions:</p>
101
 
<pre>     XbelReader(QTreeWidget *treeWidget);
102
 
     ...
103
 
     void readUnknownElement();
104
 
     void readXBEL();
105
 
     void readTitle(QTreeWidgetItem *item);
106
 
     void readSeparator(QTreeWidgetItem *item);
107
 
     void readFolder(QTreeWidgetItem *item);
108
 
     void readBookmark(QTreeWidgetItem *item);
109
 
 
110
 
     QTreeWidgetItem *createChildItem(QTreeWidgetItem *item);
111
 
 
112
 
     QTreeWidget *treeWidget;
113
 
     ...</pre>
114
 
<p>The <tt>read()</tt> function accepts a <a href="qiodevice.html">QIODevice</a> and sets it with <a href="qxmlstreamreader.html#setDevice">setDevice()</a>. The <a href="qxmlstreamreader.html#raiseError">raiseError()</a> function is used to display a custom error message, inidicating that the file's version is incorrect.</p>
115
 
<pre> bool XbelReader::read(QIODevice *device)
116
 
 {
117
 
     setDevice(device);
118
 
 
119
 
     while (!atEnd()) {
120
 
         readNext();
121
 
 
122
 
         if (isStartElement()) {
123
 
             if (name() == &quot;xbel&quot; &amp;&amp; attributes().value(&quot;version&quot;) == &quot;1.0&quot;)
124
 
                 readXBEL();
125
 
             else
126
 
                 raiseError(QObject::tr(&quot;The file is not an XBEL version 1.0 file.&quot;));
127
 
         }
128
 
     }
129
 
 
130
 
     return !error();
131
 
 }</pre>
132
 
<p>The pendent to <a href="qxmlstreamreader.html">QXmlStreamReader</a> is <a href="qxmlstreamwriter.html">QXmlStreamWriter</a>, which provides an XML writer with a simple streaming API. <a href="qxmlstreamwriter.html">QXmlStreamWriter</a> operates on a <a href="qiodevice.html">QIODevice</a> and has specialised functions for all XML tokens or events you want to write, such as <a href="qxmlstreamwriter.html#writeDTD">writeDTD()</a>, <a href="qxmlstreamwriter.html#writeCharacters">writeCharacters()</a>, <a href="qxmlstreamwriter.html#writeComment">writeComment()</a> and so on.</p>
133
 
<p>To write XML document with <a href="qxmlstreamwriter.html">QXmlStreamWriter</a>, you start a document with the <a href="qxmlstreamwriter.html#writeStartDocument">writeStartDocument()</a> function and end it with <a href="qxmlstreamwriter.html#writeEndDocument">writeEndDocument()</a>, which implicitly closes all remaining open tags. Element tags are opened with <a href="qxmlstreamwriter.html#writeStartDocument">writeStartDocument()</a> and followed by <a href="qxmlstreamwriter.html#writeAttribute">writeAttribute()</a> or <a href="qxmlstreamwriter.html#writeAttributes">writeAttributes()</a>, element content, and then <a href="qxmlstreamwriter.html#writeEndDocument">writeEndDocument()</a>. Also, <a href="qxmlstreamwriter.html#writeEmptyElement">writeEmptyElement()</a> can be used to write empty elements.</p>
134
 
<p>Element content comprises characters, entity references or nested elements. Content can be written with <a href="qxmlstreamwriter.html#writeCharacters">writeCharacters()</a>, a function that also takes care of escaping all forbidden characters and character sequences, <a href="qxmlstreamwriter.html#writeEntityReference">writeEntityReference()</a>, or subsequent calls to <a href="qxmlstreamwriter.html#writeStartElement">writeStartElement()</a>.</p>
135
 
<p>The <tt>XbelWriter</tt> class from <a href="xml-streambookmarks.html">QXmlStream Bookmarks Example</a> is a subclass of <a href="qxmlstreamwriter.html">QXmlStreamWriter</a>. Its <tt>writeFile()</tt> function illustrates the core functions of <a href="qxmlstreamwriter.html">QXmlStreamWriter</a> mentioned above:</p>
136
 
<pre> bool XbelWriter::writeFile(QIODevice *device)
137
 
 {
138
 
     setDevice(device);
139
 
 
140
 
     writeStartDocument();
141
 
     writeDTD(&quot;&lt;!DOCTYPE xbel&gt;&quot;);
142
 
     writeStartElement(&quot;xbel&quot;);
143
 
     writeAttribute(&quot;version&quot;, &quot;1.0&quot;);
144
 
     for (int i = 0; i &lt; treeWidget-&gt;topLevelItemCount(); ++i)
145
 
         writeItem(treeWidget-&gt;topLevelItem(i));
146
 
 
147
 
     writeEndDocument();
148
 
     return true;
149
 
 }</pre>
150
 
<a name="the-qt-sax2-classes"></a>
151
 
<h3>The Qt SAX2 Classes</h3>
152
 
<a name="introduction-to-sax2"></a>
153
 
<h4>Introduction to SAX2</h4>
154
 
<p>The SAX2 interface is an event-driven mechanism to provide the user with document information. An &quot;event&quot; in this context means something reported by the parser, for example, it has encountered a start tag, or an end tag, etc.</p>
155
 
<p>To make it less abstract consider the following example:</p>
156
 
<pre> &lt;quote&gt;A quotation.&lt;/quote&gt;</pre>
157
 
<p>Whilst reading (a SAX2 parser is usually referred to as &quot;reader&quot;) the above document three events would be triggered:</p>
158
 
<ol type="1">
159
 
<li>A start tag occurs (<tt>&lt;quote&gt;</tt>).</li>
160
 
<li>Character data (i.e&#x2e; text) is found, &quot;A quotation.&quot;&#x2e;</li>
161
 
<li>An end tag is parsed (<tt>&lt;/quote&gt;</tt>).</li>
162
 
</ol>
163
 
<p>Each time such an event occurs the parser reports it; you can set up event handlers to respond to these events.</p>
164
 
<p>Whilst this is a fast and simple approach to read XML documents, manipulation is difficult because data is not stored, simply handled and discarded serially. The <a href="#dom">DOM interface</a> reads in and stores the whole document in a tree structure; this takes more memory, but makes it easier to manipulate the document's structure..</p>
165
 
<p>The Qt XML module provides an abstract class, <a href="qxmlreader.html">QXmlReader</a>, that defines the interface for potential SAX2 readers. Qt includes a reader implementation, <a href="qxmlsimplereader.html">QXmlSimpleReader</a>, that is easy to adapt through subclassing.</p>
166
 
<p>The reader reports parsing events through special handler classes:</p>
167
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
168
 
<thead><tr valign="top" class="qt-style"><th>Handler class</th><th>Description</th></tr></thead>
169
 
<tr valign="top" class="odd"><td><a href="qxmlcontenthandler.html">QXmlContentHandler</a></td><td>Reports events related to the content of a document (e.g&#x2e; the start tag or characters).</td></tr>
170
 
<tr valign="top" class="even"><td><a href="qxmldtdhandler.html">QXmlDTDHandler</a></td><td>Reports events related to the DTD (e.g&#x2e; notation declarations).</td></tr>
171
 
<tr valign="top" class="odd"><td><a href="qxmlerrorhandler.html">QXmlErrorHandler</a></td><td>Reports errors or warnings that occurred during parsing.</td></tr>
172
 
<tr valign="top" class="even"><td><a href="qxmlentityresolver.html">QXmlEntityResolver</a></td><td>Reports external entities during parsing and allows users to resolve external entities themselves instead of leaving it to the reader.</td></tr>
173
 
<tr valign="top" class="odd"><td><a href="qxmldeclhandler.html">QXmlDeclHandler</a></td><td>Reports further DTD related events (e.g&#x2e; attribute declarations).</td></tr>
174
 
<tr valign="top" class="even"><td><a href="qxmllexicalhandler.html">QXmlLexicalHandler</a></td><td>Reports events related to the lexical structure of the document (the beginning of the DTD, comments etc.)&#x2e;</td></tr>
175
 
</table></p>
176
 
<p>These classes are abstract classes describing the interface. The <a href="qxmldefaulthandler.html">QXmlDefaultHandler</a> class provides a &quot;do nothing&quot; default implementation for all of them. Therefore users only need to overload the <a href="qxmldefaulthandler.html">QXmlDefaultHandler</a> functions they are interested in.</p>
177
 
<p>To read input XML data a special class <a href="qxmlinputsource.html">QXmlInputSource</a> is used.</p>
178
 
<p>Apart from those already mentioned, the following SAX2 support classes provide additional useful functionality:</p>
179
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
180
 
<thead><tr valign="top" class="qt-style"><th>Class</th><th>Description</th></tr></thead>
181
 
<tr valign="top" class="odd"><td><a href="qxmlattributes.html">QXmlAttributes</a></td><td>Used to pass attributes in a start element event.</td></tr>
182
 
<tr valign="top" class="even"><td><a href="qxmllocator.html">QXmlLocator</a></td><td>Used to obtain the actual parsing position of an event.</td></tr>
183
 
<tr valign="top" class="odd"><td><a href="qxmlnamespacesupport.html">QXmlNamespaceSupport</a></td><td>Used to implement namespace support for a reader. Note that namespaces do not change the parsing behavior. They are only reported through the handler.</td></tr>
184
 
</table></p>
185
 
<p>The <a href="xml-saxbookmarks.html">SAX Bookmarks example</a> illustrates how to subclass <a href="qxmldefaulthandler.html">QXmlDefaultHandler</a> to read an XML bookmark file (XBEL) and how to generate XML by hand.</p>
186
 
<a name="sax2-features"></a>
187
 
<h4>SAX2 Features</h4>
188
 
<p>The behavior of an XML reader depends on its support for certain optional features. For example, a reader may have the feature &quot;report attributes used for namespace declarations and prefixes along with the local name of a tag&quot;. Like every other feature this has a unique name represented by a URI: it is called <i>http://xml.org/sax/features/namespace-prefixes</i>.</p>
189
 
<p>The Qt SAX2 implementation can report whether the reader has particular functionality using the <a href="qxmlreader.html#hasFeature">QXmlReader::hasFeature</a>() function. Available features can be tested with <a href="qxmlreader.html#feature">QXmlReader::feature</a>(), and switched on or off using <a href="qxmlreader.html#setFeature">QXmlReader::setFeature</a>().</p>
190
 
<p>Consider the example</p>
191
 
<pre> &lt;document xmlns:book = 'http://qtsoftware.com/fnord/book/'
192
 
           xmlns      = 'http://qtsoftware.com/fnord/' &gt;</pre>
193
 
<p>A reader that does not support the <i>http://xml.org/sax/features/namespace-prefixes</i> feature would report the element name <i>document</i> but not its attributes <i>xmlns:book</i> and <i>xmlns</i> with their values. A reader with the feature <i>http://xml.org/sax/features/namespace-prefixes</i> reports the namespace attributes if the <a href="qxmlreader.html#feature">feature</a> is switched on.</p>
194
 
<p>Other features include <i>http://xml.org/sax/features/namespace</i> (namespace processing, implies <i>http://xml.org/sax/features/namespace-prefixes</i>) and <i>http://xml.org/sax/features/validation</i> (the ability to report validation errors).</p>
195
 
<p>Whilst SAX2 leaves it to the user to define and implement whatever features are required, support for <i>http://xml.org/sax/features/namespace</i> (and thus <i>http://xml.org/sax/features/namespace-prefixes</i>) is mandantory. The <a href="qxmlsimplereader.html">QXmlSimpleReader</a> implementation of <a href="qxmlreader.html">QXmlReader</a>, supports them, and can do namespace processing.</p>
196
 
<p><a href="qxmlsimplereader.html">QXmlSimpleReader</a> is not validating, so it does not support <i>http://xml.org/sax/features/validation</i>.</p>
197
 
<a name="namespace-support-via-features"></a>
198
 
<h4>Namespace Support via Features</h4>
199
 
<p>As we have seen in the previous section, we can configure the behavior of the reader when it comes to namespace processing. This is done by setting and unsetting the <i>http://xml.org/sax/features/namespaces</i> and <i>http://xml.org/sax/features/namespace-prefixes</i> features.</p>
200
 
<p>They influence the reporting behavior in the following way:</p>
201
 
<ol type="1">
202
 
<li>Namespace prefixes and local parts of elements and attributes can be reported.</li>
203
 
<li>The qualified names of elements and attributes are reported.</li>
204
 
<li><a href="qxmlcontenthandler.html#startPrefixMapping">QXmlContentHandler::startPrefixMapping</a>() and <a href="qxmlcontenthandler.html#endPrefixMapping">QXmlContentHandler::endPrefixMapping</a>() are called by the reader.</li>
205
 
<li>Attributes that declare namespaces (i.e&#x2e; the attribute <i>xmlns</i> and attributes starting with <i>xmlns:</i>) are reported.</li>
206
 
</ol>
207
 
<p>Consider the following element:</p>
208
 
<pre> &lt;author xmlns:fnord = 'http://qtsoftware.com/fnord/'
209
 
              title=&quot;Ms&quot;
210
 
              fnord:title=&quot;Goddess&quot;
211
 
              name=&quot;Eris Kallisti&quot;/&gt;</pre>
212
 
<p>With <i>http://xml.org/sax/features/namespace-prefixes</i> set to true the reader will report four attributes; but with the <i>namespace-prefixes</i> feature set to false only three, with the <i>xmlns:fnord</i> attribute defining a namespace being &quot;invisible&quot; to the reader.</p>
213
 
<p>The <i>http://xml.org/sax/features/namespaces</i> feature is responsible for reporting local names, namespace prefixes and URIs. With <i>http://xml.org/sax/features/namespaces</i> set to true the parser will report <i>title</i> as the local name of the <i>fnord:title</i> attribute, <i>fnord</i> being the namespace prefix and <i>http://www.qtsoftware.com/fnord/</i> as the namespace URI. When <i>http://xml.org/sax/features/namespaces</i> is false none of them are reported.</p>
214
 
<p>In the current implementation the Qt XML classes follow the definition that the prefix <i>xmlns</i> itself isn't associated with any namespace at all (see <a href="http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-using">http://www.w3.org/TR/1999/REC-xml-names-19990114/#ns-using</a>). Therefore even with <i>http://xml.org/sax/features/namespaces</i> and <i>http://xml.org/sax/features/namespace-prefixes</i> both set to true the reader won't return either a local name, a namespace prefix or a namespace URI for <i>xmlns:fnord</i>.</p>
215
 
<p>This might be changed in the future following the W3C suggestion <a href="http://www.w3.org/2000/xmlns/">http://www.w3.org/2000/xmlns/</a> to associate <i>xmlns</i> with the namespace <i>http://www.w3.org/2000/xmlns</i>.</p>
216
 
<p>As the SAX2 standard suggests, <a href="qxmlsimplereader.html">QXmlSimpleReader</a> defaults to having <i>http://xml.org/sax/features/namespaces</i> set to true and <i>http://xml.org/sax/features/namespace-prefixes</i> set to false. When changing this behavior using <a href="qxmlsimplereader.html#setFeature">QXmlSimpleReader::setFeature</a>() note that the combination of both features set to false is illegal.</p>
217
 
<a name="summary"></a>
218
 
<h5>Summary</h5>
219
 
<p><a href="qxmlsimplereader.html">QXmlSimpleReader</a> implements the following behavior:</p>
220
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
221
 
<thead><tr valign="top" class="qt-style"><th>(namespaces, namespace-prefixes)</th><th>Namespace prefix and local part</th><th>Qualified names</th><th>Prefix mapping</th><th>xmlns attributes</th></tr></thead>
222
 
<tr valign="top" class="odd"><td>(true, false)</td><td>Yes</td><td>Yes*</td><td>Yes</td><td>No</td></tr>
223
 
<tr valign="top" class="even"><td>(true, true)</td><td>Yes</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
224
 
<tr valign="top" class="odd"><td>(false, true)</td><td>No*</td><td>Yes</td><td>No*</td><td>Yes</td></tr>
225
 
<tr valign="top" class="even"><td>(false, false)</td><td colspan="4">Illegal</td></tr>
226
 
</table></p>
227
 
<p>The behavior of the entries marked with an asterisk (*) is not specified by SAX.</p>
228
 
<a name="properties"></a>
229
 
<h4>Properties</h4>
230
 
<p>Properties are a more general concept. They have a unique name, represented as an URI, but their value is <tt>void*</tt>. Thus nearly anything can be used as a property value. This concept involves some danger, though: there is no means of ensuring type-safety; the user must take care that they pass the right type. Properties are useful if a reader supports special handler classes.</p>
231
 
<p>The URIs used for features and properties often look like URLs, e.g&#x2e; <tt>http:<span class="comment">//xml.org/sax/features/namespace</span></tt>. This does not mean that the data required is at this address. It is simply a way of defining unique names.</p>
232
 
<p>Anyone can define and use new SAX2 properties for their readers. Property support is not mandatory.</p>
233
 
<p>To set or query properties the following functions are provided: <a href="qxmlreader.html#setProperty">QXmlReader::setProperty</a>(), <a href="qxmlreader.html#property">QXmlReader::property</a>() and <a href="qxmlreader.html#hasProperty">QXmlReader::hasProperty</a>().</p>
234
 
<a name="dom"></a><a name="the-qt-dom-classes"></a>
235
 
<h3>The Qt DOM Classes</h3>
236
 
<a name="domintro"></a><a name="introduction-to-dom"></a>
237
 
<h4>Introduction to DOM</h4>
238
 
<p>DOM provides an interface to access and change the content and structure of an XML file. It makes a hierarchical view of the document (a tree view). Thus -- in contrast to the SAX2 interface -- an object model of the document is resident in memory after parsing which makes manipulation easy.</p>
239
 
<p>All DOM nodes in the document tree are subclasses of <a href="qdomnode.html">QDomNode</a>. The document itself is represented as a <a href="qdomdocument.html">QDomDocument</a> object.</p>
240
 
<p>Here are the available node classes and their potential child classes:</p>
241
 
<ul>
242
 
<li><a href="qdomdocument.html">QDomDocument</a>: Possible children are<ul>
243
 
<li><a href="qdomelement.html">QDomElement</a> (at most one)</li>
244
 
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></li>
245
 
<li><a href="qdomcomment.html">QDomComment</a></li>
246
 
<li><a href="qdomdocumenttype.html">QDomDocumentType</a></li>
247
 
</ul>
248
 
</li>
249
 
<li><a href="qdomdocumentfragment.html">QDomDocumentFragment</a>: Possible children are<ul>
250
 
<li><a href="qdomelement.html">QDomElement</a></li>
251
 
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></li>
252
 
<li><a href="qdomcomment.html">QDomComment</a></li>
253
 
<li><a href="qdomtext.html">QDomText</a></li>
254
 
<li><a href="qdomcdatasection.html">QDomCDATASection</a></li>
255
 
<li><a href="qdomentityreference.html">QDomEntityReference</a></li>
256
 
</ul>
257
 
</li>
258
 
<li><a href="qdomdocumenttype.html">QDomDocumentType</a>: No children</li>
259
 
<li><a href="qdomentityreference.html">QDomEntityReference</a>: Possible children are<ul>
260
 
<li><a href="qdomelement.html">QDomElement</a></li>
261
 
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></li>
262
 
<li><a href="qdomcomment.html">QDomComment</a></li>
263
 
<li><a href="qdomtext.html">QDomText</a></li>
264
 
<li><a href="qdomcdatasection.html">QDomCDATASection</a></li>
265
 
<li><a href="qdomentityreference.html">QDomEntityReference</a></li>
266
 
</ul>
267
 
</li>
268
 
<li><a href="qdomelement.html">QDomElement</a>: Possible children are<ul>
269
 
<li><a href="qdomelement.html">QDomElement</a></li>
270
 
<li><a href="qdomtext.html">QDomText</a></li>
271
 
<li><a href="qdomcomment.html">QDomComment</a></li>
272
 
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></li>
273
 
<li><a href="qdomcdatasection.html">QDomCDATASection</a></li>
274
 
<li><a href="qdomentityreference.html">QDomEntityReference</a></li>
275
 
</ul>
276
 
</li>
277
 
<li><a href="qdomattr.html">QDomAttr</a>: Possible children are<ul>
278
 
<li><a href="qdomtext.html">QDomText</a></li>
279
 
<li><a href="qdomentityreference.html">QDomEntityReference</a></li>
280
 
</ul>
281
 
</li>
282
 
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a>: No children</li>
283
 
<li><a href="qdomcomment.html">QDomComment</a>: No children</li>
284
 
<li><a href="qdomtext.html">QDomText</a>: No children</li>
285
 
<li><a href="qdomcdatasection.html">QDomCDATASection</a>: No children</li>
286
 
<li><a href="qdomentity.html">QDomEntity</a>: Possible children are<ul>
287
 
<li><a href="qdomelement.html">QDomElement</a></li>
288
 
<li><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a></li>
289
 
<li><a href="qdomcomment.html">QDomComment</a></li>
290
 
<li><a href="qdomtext.html">QDomText</a></li>
291
 
<li><a href="qdomcdatasection.html">QDomCDATASection</a></li>
292
 
<li><a href="qdomentityreference.html">QDomEntityReference</a></li>
293
 
</ul>
294
 
</li>
295
 
<li><a href="qdomnotation.html">QDomNotation</a>: No children</li>
296
 
</ul>
297
 
<p>With <a href="qdomnodelist.html">QDomNodeList</a> and <a href="qdomnamednodemap.html">QDomNamedNodeMap</a> two collection classes are provided: <a href="qdomnodelist.html">QDomNodeList</a> is a list of nodes, and <a href="qdomnamednodemap.html">QDomNamedNodeMap</a> is used to handle unordered sets of nodes (often used for attributes).</p>
298
 
<p>The <a href="qdomimplementation.html">QDomImplementation</a> class allows the user to query features of the DOM implementation.</p>
299
 
<p>To get started please refer to the <a href="qdomdocument.html">QDomDocument</a> documentation. You might also want to take a look at the <a href="xml-dombookmarks.html">DOM Bookmarks example</a>, which illustrates how to read and write an XML bookmark file (XBEL) using DOM.</p>
300
 
<a name="namespaces"></a><a name="an-introduction-to-namespaces"></a>
301
 
<h3>An Introduction to Namespaces</h3>
302
 
<p>Parts of the Qt XML module documentation assume that you are familiar with XML namespaces. Here we present a brief introduction; skip to <a href="#namespacesconventions">Qt XML documentation conventions</a> if you already know this material.</p>
303
 
<p>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.</p>
304
 
<p>Consider the following example:</p>
305
 
<pre> &lt;document&gt;
306
 
 &lt;book&gt;
307
 
   &lt;title&gt;Practical XML&lt;/title&gt;
308
 
   &lt;author title=&quot;Ms&quot; name=&quot;Eris Kallisti&quot;/&gt;
309
 
   &lt;chapter&gt;
310
 
     &lt;title&gt;A Namespace Called fnord&lt;/title&gt;
311
 
   &lt;/chapter&gt;
312
 
 &lt;/book&gt;
313
 
 &lt;/document&gt;</pre>
314
 
<p>Here we find three different uses of the name <i>title</i>. If you wish to process this document you will encounter problems because each of the <i>titles</i> should be displayed in a different manner -- even though they have the same name.</p>
315
 
<p>The solution would be to have some means of identifying the first occurrence of <i>title</i> as the title of a book, i.e&#x2e; to use the <i>title</i> element of a book namespace to distinguish it from, for example, the chapter title, e.g&#x2e;:</p>
316
 
<pre> &lt;book:title&gt;Practical XML&lt;/book:title&gt;</pre>
317
 
<p><i>book</i> in this case is a <i>prefix</i> denoting the namespace.</p>
318
 
<p>Before we can apply a namespace to element or attribute names we must declare it.</p>
319
 
<p>Namespaces are URIs like <i>http://www.qtsoftware.com/fnord/book/</i>. This does not mean that data must be available at this address; the URI is simply used to provide a unique name.</p>
320
 
<p>We declare namespaces in the same way as attributes; strictly speaking they <i>are</i> attributes. To make for example <i>http://www.qtsoftware.com/fnord/</i> the document's default XML namespace <i>xmlns</i> we write</p>
321
 
<pre> xmlns=&quot;http://qtsoftware.com/fnord/&quot;</pre>
322
 
<p>To distinguish the <i>http://www.qtsoftware.com/fnord/book/</i> namespace from the default, we must supply it with a prefix:</p>
323
 
<pre> xmlns:book=&quot;http://qtsoftware.com/fnord/book/&quot;</pre>
324
 
<p>A namespace that is declared like this can be applied to element and attribute names by prepending the appropriate prefix and a &quot;:&quot; delimiter. We have already seen this with the <i>book:title</i> element.</p>
325
 
<p>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 &quot;traditional&quot; namespace of the element in which they appear. A &quot;traditional&quot; 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.</p>
326
 
<p>Due to the fact that attributes without prefixes are not in any XML namespace there is no collision between the attribute <i>title</i> (that belongs to the <i>author</i> element) and for example the <i>title</i> element within a <i>chapter</i>.</p>
327
 
<p>Let's clarify this with an example:</p>
328
 
<pre> &lt;document xmlns:book = 'http://qtsoftware.com/fnord/book/'
329
 
           xmlns      = 'http://qtsoftware.com/fnord/' &gt;
330
 
 &lt;book&gt;
331
 
   &lt;book:title&gt;Practical XML&lt;/book:title&gt;
332
 
   &lt;book:author xmlns:fnord = 'http://qtsoftware.com/fnord/'
333
 
                title=&quot;Ms&quot;
334
 
                fnord:title=&quot;Goddess&quot;
335
 
                name=&quot;Eris Kallisti&quot;/&gt;
336
 
   &lt;chapter&gt;
337
 
     &lt;title&gt;A Namespace Called fnord&lt;/title&gt;
338
 
   &lt;/chapter&gt;
339
 
 &lt;/book&gt;
340
 
 &lt;/document&gt;</pre>
341
 
<p>Within the <i>document</i> element we have two namespaces declared. The default namespace <i>http://www.qtsoftware.com/fnord/</i> applies to the <i>book</i> element, the <i>chapter</i> element, the appropriate <i>title</i> element and of course to <i>document</i> itself.</p>
342
 
<p>The <i>book:author</i> and <i>book:title</i> elements belong to the namespace with the URI <i>http://www.qtsoftware.com/fnord/book/</i>.</p>
343
 
<p>The two <i>book:author</i> attributes <i>title</i> and <i>name</i> have no XML namespace assigned. They are only members of the &quot;traditional&quot; namespace of the element <i>book:author</i>, meaning that for example two <i>title</i> attributes in <i>book:author</i> are forbidden.</p>
344
 
<p>In the above example we circumvent the last rule by adding a <i>title</i> attribute from the <i>http://www.qtsoftware.com/fnord/</i> namespace to <i>book:author</i>: the <i>fnord:title</i> comes from the namespace with the prefix <i>fnord</i> that is declared in the <i>book:author</i> element.</p>
345
 
<p>Clearly the <i>fnord</i> 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:</p>
346
 
<ul>
347
 
<li>attributes without a prefix don't belong to any XML namespace at all, not even to the default namespace;</li>
348
 
<li>additionally omitting the prefix would lead to a <i>title-title</i> clash;</li>
349
 
<li>writing it as <i>xmlns:title</i> would declare a new namespace with the prefix <i>title</i> instead of applying the default <i>xmlns</i> namespace.</li>
350
 
</ul>
351
 
<p>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 &quot;real&quot; name (or <i>local</i> name) or by the combination of local name and namespace URI.</p>
352
 
<p>More information on XML namespaces can be found at <a href="http://www.w3.org/TR/REC-xml-names/">http://www.w3.org/TR/REC-xml-names/</a>.</p>
353
 
<a name="namespacesconventions"></a><a name="conventions-used-in-the-qt-xml-documentation"></a>
354
 
<h4>Conventions Used in the Qt XML Documentation</h4>
355
 
<p>The following terms are used to distinguish the parts of names within the context of namespaces:</p>
356
 
<ul>
357
 
<li>The <i>qualified name</i> is the name as it appears in the document. (In the above example <i>book:title</i> is a qualified name.)</li>
358
 
<li>A <i>namespace prefix</i> in a qualified name is the part to the left of the &quot;:&quot;. (<i>book</i> is the namespace prefix in <i>book:title</i>.)</li>
359
 
<li>The <i>local part</i> of a name (also refered to as the <i>local name</i>) appears to the right of the &quot;:&quot;. (Thus <i>title</i> is the local part of <i>book:title</i>.)</li>
360
 
<li>The <i>namespace URI</i> (&quot;Uniform Resource Identifier&quot;) is a unique identifier for a namespace. It looks like a URL (e.g&#x2e; <i>http://www.qtsoftware.com/fnord/</i> ) but does not require data to be accessible by the given protocol at the named address.</li>
361
 
</ul>
362
 
<p>Elements without a &quot;:&quot; (like <i>chapter</i> in the example) do not have a namespace prefix. In this case the local part and the qualified name are identical (i.e&#x2e; <i>chapter</i>).</p>
363
 
<p>See also <a href="xml-dombookmarks.html">DOM Bookmarks Example</a> and <a href="xml-saxbookmarks.html">SAX Bookmarks Example</a>.</p>
 
67
<p>Further XML support is provided by the <a href="http://qt.nokia.com/products/add-on-products">Qt Solutions</a> group who provide, for example, classes that support SOAP and MML with the Qt XML classes.</p>
 
68
<p>This module is part of the <a href="full-framework-edition-classes.html">Qt Full Framework Edition</a> and the <a href="opensourceedition.html">Open Source Versions of Qt</a>.</p>
364
69
<p>
365
70
[Previous: <a href="qtsvg.html">QtSvg Module</a>]
366
 
[<a href="modules.html">Qt's Modules</a>]
 
71
[<a href="modules.html">All Qt Modules</a>]
367
72
[Next: <a href="qtxmlpatterns.html">QtXmlPatterns Module</a>]
368
73
</p>
369
74
<p /><address><hr /><div align="center">
370
75
<table width="100%" cellspacing="0" border="0"><tr class="address">
371
 
<td width="30%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
372
 
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
373
 
<td width="30%" align="right"><div align="right">Qt 4.5.2</div></td>
374
 
</tr></table></div></address></body>
 
76
<td width="40%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
 
77
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
78
<td width="40%" align="right"><div align="right">Qt 4.6.0</div></td>
 
79
<script type="text/javascript" src="http://www.google.com/jsapi"></script><script type="text/javascript">google.load("elements", "1", {packages: "transliteration"});</script><script type="text/javascript" src="http://www.google.com/coop/cse/t13n?form=cse-search-box&t13n_langs=en"></script><script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=cse-search-box&lang=en"></script></tr></table></div></address></body>
375
80
</html>