File: xml.html

package info (click to toggle)
qt-embedded 2.3.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 68,608 kB
  • ctags: 45,998
  • sloc: cpp: 276,654; ansic: 71,987; makefile: 29,074; sh: 12,305; yacc: 2,465; python: 1,863; perl: 481; lex: 480; xml: 68; lisp: 15
file content (223 lines) | stat: -rw-r--r-- 9,867 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit -  Qt XML Module</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style></head><body bgcolor="#ffffff">
<p>
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center> Qt XML Module</h1><br clear="all">
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).
<p>
This document assumes that you are familiar with the essentials of XML. It
provides you with information on the XML module in Qt
and explains some often neglected XML features that 
will help you make the best use of the Qt XML classes. 
<p>
We will however not teach XML basics. If you wish to learn 
more about XML please refer to other sources,
e.g. <a href="http://www.w3.org/XML/">http://www.w3.org/XML/</a>.
<p>
<h2><a name="overview">Overview of the XML architecture in Qt</a></h2>
<p>
The Qt XML Module provides two interfaces for XML: SAX2 and DOM Level 2.
<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.megginson.com/SAX/">http://www.megginson.com/SAX/</a>.
<p>
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. 
<p>
For an introduction to Qt's SAX2 classes see
"<a href="xml-sax.html">The Qt SAX2 implementation</a>". 
A code example is discussed in the "<a href="xml-sax-walkthrough.html">tagreader
walkthrough</a>".
<p>
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
<a href="http://www.w3.org/DOM/">http://www.w3.org/DOM/</a>.
More information about the DOM classes in Qt is provided in the
<a href="xml-dom.html">Qt XML DOM overview</a>.
<p>
<h2><a name="namespaces">An introduction to namespaces</a></h2>
<p>
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.
<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>
Consider the following example:
<p>
<pre>&lt;document&gt;
&lt;book&gt;
  &lt;title&gt;Practical XML&lt;/title&gt;
  &lt;author title="Ms" name="Eris Kallisti"/&gt;
  &lt;chapter&gt;
    &lt;title&gt;A Namespace Called fnord&lt;/title&gt;  
  &lt;/chapter&gt; 
&lt;/book&gt;
&lt;/document&gt;
</pre>
<p>
Here we find three different uses of the name <em>title.</em> If you wish
to process this document you will encounter problems
because each of the <em>titles</em> should be displayed in a different manner --
even though they have the same name.
<p>
The solution would be to have some means of identifying the 
first occurence of <em>title</em> as the title of a book, i.e. 
to use the <em>title</em> element of a 
book namespace to distinguish it from for example the chapter title, e.g.:
<pre>&lt;book:title&gt;Practical XML&lt;/book:title&gt;
</pre>
<p>
<em>book</em> in this case is
a <em>prefix</em> denoting the namespace.
<p>
Before we can apply a
namespace to element or attribute names we must declare it.
<p>
Namespaces are URIs like <em>http://trolltech.com/fnord/book/.</em>
This does not mean that data must be available at this
address; the URI is simply used to provide a unique name.
<p>
We declare namespaces in the same way as 
attributes; strictly speaking they <em>are</em> attributes. 
To make for example <em>http://trolltech.com/fnord/</em> the document's
default XML namespace <em>xmlns</em> we write
<p>
<pre>xmlns="http://trolltech.com/fnord/"
</pre>
<p>
To distinguish the <em>http://trolltech.com/fnord/book/</em> namespace
from the default, we have to supply it with a prefix:
<p>
<pre>xmlns:book="http://trolltech.com/fnord/book/"
</pre>
<p>
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 <em>book:title</em> element.
<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 "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.
<p>
Due to the fact that attributes without prefixes are not in any 
XML namespace there is 
no collision between the attribute <em>title</em> (that belongs to the 
<em>author</em> element) and for example the <em>title</em> element within a <em>chapter.</em>
<p>
Lets clarify matters with an example:
<pre>&lt;document xmlns:book = 'http://trolltech.com/fnord/book/'
          xmlns      = 'http://trolltech.com/fnord/' &gt;
&lt;book&gt;
  &lt;book:title&gt;Practical XML&lt;/book:title&gt;
  &lt;book:author xmlns:fnord = 'http://trolltech.com/fnord/'
               title="Ms" 
               fnord:title="Goddess" 
               name="Eris Kallisti"/&gt;
  &lt;chapter&gt;
    &lt;title&gt;A Namespace Called fnord&lt;/title&gt;
  &lt;/chapter&gt;
&lt;/book&gt;
&lt;/document&gt;
</pre>
<p>
Within the <em>document</em> element we have two namespaces declared.
The default namespace <em>http://trolltech.com/fnord/</em> 
applies to the <em>book</em> element, the <em>chapter</em> element,
the appropriate <em>title</em> element and of course to <em>document</em> itself.
<p>
The <em>book:author</em> and <em>book:title</em> elements 
belong to the namespace with the
URI <em>http://trolltech.com/fnord/book/.</em>
<p>
The two <em>book:author</em> attributes <em>title</em> and <em>name</em> have no XML namespace
assigned. 
They are only members of the "traditional" namespace of the element
<em>book:author,</em> meaning that for example two <em>title</em> attributes 
in <em>book:author</em> are forbidden.
<p>
In the above example we circumvent the last rule by adding a <em>title</em>
attribute from the <em>http://trolltech.com/fnord/</em> namespace to <em>book:author:</em> 
the <em>fnord:title</em> comes from the namespace with the prefix <em>fnord</em>
that is declared in the <em>book:author</em> element. 
<p>
Clearly the <em>fnord</em> 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:
<UL>
<LI>attributes without a prefix don't belong to any XML namespace at all,
even not to the default namespace;
<LI>additionaly omitting the prefix would lead to a <em>title-title</em> clash;
<LI>writing it as <em>xmlns:title</em> would declare a new namespace with
the prefix <em>title</em> instead of applying the default <em>xmlns</em> namespace. 
</UL>
<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 "real" name (or <em>local</em> name) or 
by the combination of local name and namespace URI.
<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>
<h2><a name="conventions">Conventions used in Qt XML documentation</a></h2>
<p>
The following terms are used to distinguish the parts of names within the context of
namespaces:
<ul>
<li>The <i>qualified name</i>
    is the name as it appears in the document. (In the above example <em>book:title</em> is a qualified name.)
<li>A <i>namespace prefix</i> in a qualified name
    is the part to the left of the ":".  (<em>book</em> is the namespace prefix in 
    <em>book:title.)</em>
<li>The <i>local part</i> of a name (also refered to as the <i>local name</i>) appears 
    to the right of the ":".
    (Thus <em>title</em> is the local part of <em>book:title.)</em>
<li>The <I>namespace URI</I> ("Uniform Resource Identifier") is a unique
    identifier for a namespace. It looks like a URL
    (e.g. <em>http://trolltech.com/fnord/</em> ) but does not require 
    data to be accessible by the given protocol at the named address.
</ul>
<p>
Elements without a ":" (like <em>chapter</em> in the example) do not have a namespace
prefix. In this case the local part and the qualified name 
are identical (i.e. <em>chapter).</em>

<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright  2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>