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

« back to all changes in this revision

Viewing changes to doc/html/qtxmlpatterns.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/qtxmlpatterns.qdoc -->
 
5
<!-- modules.qdoc -->
6
6
<head>
7
 
  <title>Qt 4.5: QtXmlPatterns Module</title>
 
7
  <title>Qt 4.6: QtXmlPatterns Module</title>
8
8
  <link rel="prev" href="qtxml.html" />
9
9
  <link rel="contents" href="modules.html" />
10
10
  <link rel="next" href="phonon-module.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="qtxml.html">QtXml 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="phonon-module.html">Phonon Module</a>]
22
22
</p>
23
23
<h1 class="title">QtXmlPatterns Module<br /><span class="subtitle"></span>
24
24
</h1>
25
 
<p>An overview of Qt's support for using XQuery and XPath in Qt programs. <a href="#details">More...</a></p>
 
25
<p>The QtXmlPatterns module provides support for XPath, XQuery, XSLT and XML schema-validation. <a href="#details">More...</a></p>
26
26
<h2>Classes</h2>
27
27
<p><table width="100%" class="annotated" cellpadding="2" cellspacing="1" border="0">
28
28
<tr valign="top" class="odd"><th><a href="qabstractmessagehandler.html">QAbstractMessageHandler</a></th><td>Callback interface for handling messages</td></tr>
38
38
<tr valign="top" class="odd"><th><a href="qxmlnodemodelindex.html">QXmlNodeModelIndex</a></th><td>Identifies a node in an XML node model subclassed from QAbstractXmlNodeModel</td></tr>
39
39
<tr valign="top" class="even"><th><a href="qxmlquery.html">QXmlQuery</a></th><td>Performs XQueries on XML data, or on non-XML data modeled to look like XML</td></tr>
40
40
<tr valign="top" class="odd"><th><a href="qxmlresultitems.html">QXmlResultItems</a></th><td>Iterates through the results of evaluating an XQuery in QXmlQuery</td></tr>
 
41
<tr valign="top" class="even"><th><a href="qxmlschema.html">QXmlSchema</a></th><td>Loading and validation of a W3C XML Schema</td></tr>
 
42
<tr valign="top" class="odd"><th><a href="qxmlschemavalidator.html">QXmlSchemaValidator</a></th><td>Validates XML instance documents against a W3C XML Schema</td></tr>
41
43
<tr valign="top" class="even"><th><a href="qxmlserializer.html">QXmlSerializer</a></th><td>Implementation of QAbstractXmlReceiver for transforming XQuery output into unformatted XML</td></tr>
42
44
</table></p>
43
45
<a name="details"></a>
44
46
<h2>Detailed Description</h2>
45
 
<a name="patternist"></a><ul><li><a href="#introduction">Introduction</a></li>
46
 
<li><a href="#advantages-of-using-qtxmlpatterns-and-xquery">Advantages of using QtXmlPatterns and XQuery</a></li>
47
 
<li><a href="#using-the-qtxmlpatterns-module">Using the QtXmlPatterns module</a></li>
48
 
<ul><li><a href="#running-the-query-engine-from-your-qt-application">Running the query engine from your Qt application</a></li>
49
 
<li><a href="#running-the-query-engine-from-the-command-line-utility">Running the query engine from the command line utility</a></li>
50
 
</ul>
51
 
<li><a href="#the-xquery-data-model">The XQuery Data Model</a></li>
52
 
<ul><li><a href="#binding-program-variables-to-xquery-variables">Binding program variables to XQuery variables</a></li>
53
 
<ul><li><a href="#binding-to-qvariant-time">Binding To QVariant::Time</a></li>
54
 
<li><a href="#binding-to-qvariantlist">Binding To QVariantList</a></li>
55
 
</ul>
56
 
<li><a href="#interpreting-xquery-results">Interpreting XQuery results</a></li>
57
 
<ul><li><a href="#handling-qxmlnames">Handling QXmlNames</a></li>
58
 
<li><a href="#no-mapping-for-xs-time">No mapping for xs:time</a></li>
59
 
</ul>
60
 
</ul>
61
 
<li><a href="#using-xquery-with-non-xml-data">Using XQuery with Non-XML Data</a></li>
62
 
<li><a href="#more-on-using-qtxmlpatterns-with-non-xml-data">More on using QtXmlPatterns with non-XML Data</a></li>
63
 
<li><a href="#security-considerations">Security Considerations</a></li>
64
 
<ul><li><a href="#code-injection">Code Injection</a></li>
65
 
<li><a href="#denial-of-service-attacks">Denial of Service Attacks</a></li>
66
 
</ul>
67
 
<li><a href="#features-and-conformance">Features and Conformance</a></li>
68
 
<ul><li><a href="#xquery-1-0">XQuery 1.0</a></li>
69
 
<li><a href="#xslt-2-0">XSLT 2.0</a></li>
70
 
<li><a href="#xpath-2-0">XPath 2.0</a></li>
71
 
<li><a href="#xml-id">xml:id</a></li>
72
 
<li><a href="#resource-loading">Resource Loading</a></li>
73
 
<li><a href="#xml">XML</a></li>
74
 
</ul>
75
 
</ul>
76
 
<a name="introduction"></a>
77
 
<h3>Introduction</h3>
78
 
<p>XQuery is a language for traversing XML documents to select and aggregate items of interest and to transform them for output as XML or some other format. XPath is the <i>element selection</i> part of XQuery.</p>
79
 
<p>The QtXmlPatterns module supports using <a href="http://www.w3.org/TR/xquery">XQuery 1.0</a> and <a href="http://www.w3.org/TR/xpath20">XPath 2.0</a> in Qt applications, for querying XML data <i>and</i> for querying <a href="qabstractxmlnodemodel.html">non-XML data that can be modeled to look like XML</a>. The QtXmlPatterns module is included in 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>. Readers who are not familiar with the XQuery/XPath language can read <a href="xquery-introduction.html">A Short Path to XQuery</a> for a brief introduction.</p>
80
 
<a name="advantages-of-using-qtxmlpatterns-and-xquery"></a>
81
 
<h3>Advantages of using QtXmlPatterns and XQuery</h3>
82
 
<p>The XQuery/XPath language simplifies data searching and transformation tasks by eliminating the need for doing a lot of C++ or Java procedural programming for each new query task. Here is an XQuery that constructs a bibliography of the contents of a library:</p>
83
 
<a name="qtxmlpatterns-example-query"></a><pre> &lt;bibliography&gt;
84
 
 {doc(&quot;library.xml&quot;)/bib/book[publisher=&quot;Addison-Wesley&quot; and @year&gt;1991]/&lt;book year=&quot;{@year}&quot;&gt;{title}&lt;/book&gt;}
85
 
 &lt;/bibliography&gt;</pre>
86
 
<p>First, the query opens a <tt>&lt;bibliography&gt;</tt> element in the output. The <a href="xquery-introduction.html#using-path-expressions-to-match-select-items">embedded path expression</a> then loads the XML document describing the contents of the library (<tt>library.xml</tt>) and begins the search. For each <tt>&lt;book&gt;</tt> element it finds, where the publisher was Addison-Wesley and the publication year was after 1991, it creates a new <tt>&lt;book&gt;</tt> element in the output as a child of the open <tt>&lt;bibliography&gt;</tt> element. Each new <tt>&lt;book&gt;</tt> element gets the book's title as its contents and the book's publication year as an attribute. Finally, the <tt>&lt;bibliography&gt;</tt> element is closed.</p>
87
 
<p>The advantages of using QtXmlPatterns and XQuery in your Qt programs are summarized as follows:</p>
88
 
<ul>
89
 
<li><b>Ease of development</b>: All the C++ programming required to perform data query tasks can be replaced by a simple XQuery like the example above.</li>
90
 
<li><b>Comprehensive functionality</b>: The <a href="http://www.w3.org/TR/xquery/#id-expressions">expression syntax</a> and rich set of <a href="http://www.w3.org/TR/xpath-functions">functions and operators</a> provided by XQuery are sufficient for performing any data searching, selecting, and sorting tasks.</li>
91
 
<li><b>Conformance to standards</b>: Conformance to all applicable XML and XQuery standards ensures that QtXmlPatterns can always process XML documents generated by other conformant applications, and that XML documents created with QtXmlPatterns can be processed by other conformant applications.</li>
92
 
<li><b>Maximal flexibility</b> The QtXmlPatterns module can be used to query XML data <i>and</i> non-XML data that can be <a href="qabstractxmlnodemodel.html">modeled to look like XML</a>.</li>
93
 
</ul>
94
 
<a name="using-the-qtxmlpatterns-module"></a>
95
 
<h3>Using the QtXmlPatterns module</h3>
96
 
<p>There are two ways QtXmlPatterns can be used to evaluate queries. You can run the query engine in your Qt application using the QtXmlPatterns C++ API, or you can run the query engine from the command line using Qt's <tt>xmlpatterns</tt> command line utility.</p>
97
 
<a name="running-the-query-engine-from-your-qt-application"></a>
98
 
<h4>Running the query engine from your Qt application</h4>
99
 
<p>To access the QtXmlPatterns C++ API from your Qt application, include the QtXmlPatterns classes at compile time:</p>
 
47
<p>To include the definitions of the module's classes, use the following directive:</p>
100
48
<pre> #include &lt;QtXmlPatterns&gt;</pre>
101
 
<p>Link the compiled application with the QtXmlPatterns module by adding the following line to the <a href="qmake-project-files.html#declaring-qt-libraries">QT line</a> in your qmake <tt>.pro</tt> file:</p>
 
49
<p>To link against the module, add this line to your <a href="qmake-manual.html#qmake">qmake</a> <tt>.pro</tt> file:</p>
102
50
<pre> QT += xmlpatterns</pre>
103
 
<p>If we save the example XQuery shown above in a text file (e.g&#x2e; <tt>myquery.xq</tt>), we can run it from a Qt application using a standard QtXmlPatterns code sequence:</p>
104
 
<pre>     QFile xq(&quot;myquery.xq&quot;);
105
 
 
106
 
     QXmlQuery query;
107
 
     query.setQuery(&amp;xq, QUrl::fromLocalFile(xq.fileName()));
108
 
 
109
 
     QXmlSerializer serializer(query, myOutputDevice);
110
 
     query.evaluateTo(&amp;serializer);</pre>
111
 
<p>First construct a <a href="qfile.html">QFile</a> for the text file containing the XQuery (<tt>myquery.xq</tt>). Then create an instance of <a href="qxmlquery.html">QXmlQuery</a> and call its <a href="qxmlquery.html#setQuery">setQuery()</a> function to load and parse the XQuery file. Then create an <a href="qxmlserializer.html">XML serializer</a> to output the query's result set as unformatted XML. Finally, call the <a href="qxmlquery.html#evaluateTo">evaluateTo()</a> function to evaluate the query and serialize the results as XML.</p>
112
 
<p><b>Note:</b> If you compile Qt yourself, the QtXmlPatterns module will <i>not</i> be built if exceptions are disabled, or if you compile Qt with a compiler that doesn't support member templates, e.g&#x2e;, MSVC 6.</p>
113
 
<p>See the <a href="qxmlquery.html">QXmlQuery</a> documentation for more information about the QtXmlPatterns C++ API.</p>
114
 
<a name="running-the-query-engine-from-the-command-line-utility"></a>
115
 
<h4>Running the query engine from the command line utility</h4>
116
 
<p><i>xmlpatterns</i> is a command line utility for running XQueries. It expects the name of a file containing the XQuery text.</p>
117
 
<pre> xmlpatterns myQuery.xq</pre>
118
 
<p>The XQuery in <tt>myQuery.xq</tt> will be evaluated and its output written to <tt>stdout</tt>. Pass the <tt>-help</tt> switch to get the list of input flags and their meanings.</p>
119
 
<p>xmlpatterns can be used in scripting. However, the descriptions and messages it outputs were not meant to be parsed and may be changed in future releases of Qt.</p>
120
 
<a name="qtxdm"></a><a name="the-xquery-data-model"></a>
121
 
<h3>The XQuery Data Model</h3>
122
 
<p>XQuery represents data items as <i>atomic values</i> or <i>nodes</i>. An atomic value is a value in the domain of one of the <a href="http://www.w3.org/TR/xmlschema-2/#built-in-datatypes">built-in datatypes</a> defined in <a href="http://www.w3.org/TR/xmlschema-2">Part 2</a> of the W3C XML Schema. A node is normally an XML element or attribute, but when non-XML data is <a href="qabstractxmlnodemodel.html">modeled to look like XML</a>, a node can also represent a non-XML data items.</p>
123
 
<p>When you run an XQuery using the C++ API in a Qt application, you will often want to bind program variables to $variables in the XQuery. After the query is evaluated, you will want to interpret the sequence of data items in the result set.</p>
124
 
<a name="binding-program-variables-to-xquery-variables"></a>
125
 
<h4>Binding program variables to XQuery variables</h4>
126
 
<p>When you want to run a parameterized XQuery from your Qt application, you will need to <a href="qxmlquery.html#bindVariable">bind variables</a> in your program to $name variables in your XQuery.</p>
127
 
<p>Suppose you want to parameterize the bibliography XQuery in the example above. You could define variables for the catalog that contains the library (<tt>$file</tt>), the publisher name (<tt>$publisher</tt>), and the year of publication (<tt>$year</tt>):</p>
128
 
<a name="qtxmlpatterns-example-query2"></a><pre> &lt;bibliography&gt;
129
 
 {
130
 
     doc($file)/bib/book[publisher = $publisher and @year &gt; $year]/&lt;book year=&quot;{@year}&quot;&gt;{title}&lt;/book&gt;
131
 
 }
132
 
 &lt;/bibliography&gt;</pre>
133
 
<p>Modify the QtXmlPatterns code to use one of the <a href="qxmlquery.html#bindVariable">bindVariable()</a> functions to bind a program variable to each XQuery $variable:</p>
134
 
<pre>     QFile xq(&quot;myquery.xq&quot;);
135
 
     QString fileName(&quot;the filename&quot;);
136
 
     QString publisherName(&quot;the publisher&quot;);
137
 
     qlonglong year = 1234;
138
 
 
139
 
     QXmlQuery query;
140
 
 
141
 
     query.bindVariable(&quot;file&quot;, QVariant(fileName));
142
 
     query.bindVariable(&quot;publisher&quot;, QVariant(publisherName));
143
 
     query.bindVariable(&quot;year&quot;, QVariant(year));
144
 
 
145
 
     query.setQuery(&amp;xq, QUrl::fromLocalFile(xq.fileName()));
146
 
 
147
 
     QXmlSerializer serializer(query, myOutputDevice);
148
 
     query.evaluateTo(&amp;serializer);</pre>
149
 
<p>Each program variable is passed to QtXmlPatterns as a <a href="qvariant.html">QVariant</a> of the type of the C++ variable or constant from which it is constructed. Note that QtXmlPatterns assumes that the type of the <a href="qvariant.html">QVariant</a> in the bindVariable() call is the correct type, so the $variable it is bound to must be used in the XQuery accordingly. The following table shows how <a href="qvariant.html">QVariant</a> types are mapped to XQuery $variable types:</p>
150
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
151
 
<thead><tr valign="top" class="qt-style"><th><a href="qvariant.html">QVariant</a> type</th><th>XQuery $variable type</th></tr></thead>
152
 
<tr valign="top" class="odd"><td><a href="qvariant.html#Type-enum">QVariant::LongLong</a></td><td><tt>xs:integer</tt></td></tr>
153
 
<tr valign="top" class="even"><td><a href="qvariant.html#Type-enum">QVariant::Int</a></td><td><tt>xs:integer</tt></td></tr>
154
 
<tr valign="top" class="odd"><td><a href="qvariant.html#Type-enum">QVariant::UInt</a></td><td><tt>xs:nonNegativeInteger</tt></td></tr>
155
 
<tr valign="top" class="even"><td><a href="qvariant.html#Type-enum">QVariant::ULongLong</a></td><td><tt>xs:unsignedLong</tt></td></tr>
156
 
<tr valign="top" class="odd"><td><a href="qvariant.html#Type-enum">QVariant::String</a></td><td><tt>xs:string</tt></td></tr>
157
 
<tr valign="top" class="even"><td><a href="qvariant.html#Type-enum">QVariant::Double</a></td><td><tt>xs:double</tt></td></tr>
158
 
<tr valign="top" class="odd"><td><a href="qvariant.html#Type-enum">QVariant::Bool</a></td><td><tt>xs:boolean</tt></td></tr>
159
 
<tr valign="top" class="even"><td><a href="qvariant.html#Type-enum">QVariant::Double</a></td><td><tt>xs:decimal</tt></td></tr>
160
 
<tr valign="top" class="odd"><td><a href="qvariant.html#Type-enum">QVariant::ByteArray</a></td><td><tt>xs:base64Binary</tt></td></tr>
161
 
<tr valign="top" class="even"><td><a href="qvariant.html#Type-enum">QVariant::StringList</a></td><td><tt>xs:string*</tt></td></tr>
162
 
<tr valign="top" class="odd"><td><a href="qvariant.html#Type-enum">QVariant::Url</a></td><td><tt>xs:string</tt></td></tr>
163
 
<tr valign="top" class="even"><td><a href="qvariant.html#Type-enum">QVariant::Date</a></td><td><tt>xs:date</tt>.</td></tr>
164
 
<tr valign="top" class="odd"><td><a href="qvariant.html#Type-enum">QVariant::DateTime</a></td><td><tt>xs:dateTime</tt></td></tr>
165
 
<tr valign="top" class="even"><td><a href="qvariant.html#Type-enum">QVariant::Time</a>.</td><td><tt>xs:time</tt>. (see <a href="#binding-to-time">Binding To QVariant::Time</a> below)</td></tr>
166
 
<tr valign="top" class="odd"><td><a href="qvariant.html#QVariantList-typedef">QVariantList</a></td><td>(see <a href="#binding-to-qvariantlist">Binding To QVariantList</a> below)</td></tr>
167
 
</table></p>
168
 
<p>A type not shown in the table is not supported and will cause undefined XQuery behavior or a $variable binding error, depending on the context in the XQuery where the variable is used.</p>
169
 
<a name="binding-to-time"></a><a name="binding-to-qvariant-time"></a>
170
 
<h5>Binding To QVariant::Time</h5>
171
 
<p>Because the instance of <a href="qtime.html">QTime</a> used in <a href="qvariant.html#Type-enum">QVariant::Time</a> does not include a zone offset, an instance of <a href="qvariant.html#Type-enum">QVariant::Time</a> should not be bound to an XQuery variable of type <tt>xs:time</tt>, unless the <a href="qtime.html">QTime</a> is UTC. When binding a non-UTC <a href="qtime.html">QTime</a> to an XQuery variable, it should first be passed as a string, or converted to a <a href="qdatetime.html">QDateTime</a> with an arbitrary date, and then bound to an XQuery variable of type <tt>xs:dateTime</tt>.</p>
172
 
<a name="binding-to-qvariantlist"></a><a name="binding-to-qvariantlist"></a>
173
 
<h5>Binding To QVariantList</h5>
174
 
<p>A <a href="qvariant.html#QVariantList-typedef">QVariantList</a> can be bound to an XQuery $variable. All the <a href="qvariant.html">QVariant</a>s in the list must be of the same atomic type, and the $variable the variant list is bound to must be of that same atomic type. If the QVariants in the list are not all of the same atomic type, the XQuery behavior is undefined.</p>
175
 
<a name="interpreting-xquery-results"></a>
176
 
<h4>Interpreting XQuery results</h4>
177
 
<p>When the results of an XQuery are returned in a sequence of <a href="qxmlresultitems.html">result items</a>, atomic values in the sequence are treated as instances of <a href="qvariant.html">QVariant</a>. Suppose that instead of serializing the results of the XQuery as XML, we process the results programatically. Modify the standard QtXmlPatterns code sequence to call the overload of <a href="qxmlquery.html#evaluateTo">QXmlQuery::evaluateTo</a>() that populates a sequence of <a href="qxmlresultitems.html">result items</a> with the XQuery results:</p>
178
 
<pre>     QFile xq(&quot;myquery.xq&quot;);
179
 
     QString fileName(&quot;the filename&quot;);
180
 
     QString publisherName(&quot;the publisher&quot;);
181
 
     qlonglong year = 1234;
182
 
 
183
 
     QXmlQuery query;
184
 
 
185
 
     query.bindVariable(&quot;file&quot;, QVariant(fileName));
186
 
     query.bindVariable(&quot;publisher&quot;, QVariant(publisherName));
187
 
     query.bindVariable(&quot;year&quot;, QVariant(year));
188
 
 
189
 
     query.setQuery(&amp;xq, QUrl::fromLocalFile(xq.fileName()));
190
 
 
191
 
     QXmlResultItems result;
192
 
     query.evaluateTo(&amp;result);
193
 
     QXmlItem item(result.next());
194
 
     while (!item.isNull()) {
195
 
         if (item.isAtomicValue()) {
196
 
             QVariant v = item.toAtomicValue();
197
 
             switch (v.type()) {
198
 
                 case QVariant::LongLong:
199
 
                     <span class="comment">// xs:integer</span>
200
 
                     break;
201
 
                 case QVariant::String:
202
 
                     <span class="comment">// xs:string</span>
203
 
                     break;
204
 
                 default:
205
 
                     <span class="comment">// error</span>
206
 
                     break;
207
 
             }
208
 
         }
209
 
         else if (item.isNode()) {
210
 
             QXmlNodeModelIndex i = item.toNodeModelIndex();
211
 
             <span class="comment">// process node</span>
212
 
         }
213
 
         item = result.next();
214
 
     }</pre>
215
 
<p>Iterate through the <a href="qxmlresultitems.html">result items</a> and test each <a href="qxmlitem.html">QXmlItem</a> to see if it is an atomic value or a node. If it is an atomic value, convert it to a <a href="qvariant.html">QVariant</a> with <a href="qxmlitem.html#toAtomicValue">toAtomicValue()</a> and switch on its <a href="qvariant.html#type">variant type</a> to handle all the atomic values your XQuery might return. The following table shows the <a href="qvariant.html">QVariant</a> type to expect for each atomic value type (or <a href="qxmlname.html">QXmlName</a>):</p>
216
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
217
 
<thead><tr valign="top" class="qt-style"><th>XQuery result item type</th><th><a href="qvariant.html">QVariant</a> type returned</th></tr></thead>
218
 
<tr valign="top" class="odd"><td><tt>xs:QName</tt></td><td><a href="qxmlname.html">QXmlName</a> (see <a href="#handling-qxmlnames">Handling QXmlNames</a> below)</td></tr>
219
 
<tr valign="top" class="even"><td><tt>xs:integer</tt></td><td><a href="qvariant.html#Type-enum">QVariant::LongLong</a></td></tr>
220
 
<tr valign="top" class="odd"><td><tt>xs:string</tt></td><td><a href="qvariant.html#Type-enum">QVariant::String</a></td></tr>
221
 
<tr valign="top" class="even"><td><tt>xs:string*</tt></td><td><a href="qvariant.html#Type-enum">QVariant::StringList</a></td></tr>
222
 
<tr valign="top" class="odd"><td><tt>xs:double</tt></td><td><a href="qvariant.html#Type-enum">QVariant::Double</a></td></tr>
223
 
<tr valign="top" class="even"><td><tt>xs:float</tt></td><td><a href="qvariant.html#Type-enum">QVariant::Double</a></td></tr>
224
 
<tr valign="top" class="odd"><td><tt>xs:boolean</tt></td><td><a href="qvariant.html#Type-enum">QVariant::Bool</a></td></tr>
225
 
<tr valign="top" class="even"><td><tt>xs:decimal</tt></td><td><a href="qvariant.html#Type-enum">QVariant::Double</a></td></tr>
226
 
<tr valign="top" class="odd"><td><tt>xs:hexBinary</tt></td><td><a href="qvariant.html#Type-enum">QVariant::ByteArray</a></td></tr>
227
 
<tr valign="top" class="even"><td><tt>xs:base64Binary</tt></td><td><a href="qvariant.html#Type-enum">QVariant::ByteArray</a></td></tr>
228
 
<tr valign="top" class="odd"><td><tt>xs:gYear</tt></td><td><a href="qvariant.html#Type-enum">QVariant::DateTime</a></td></tr>
229
 
<tr valign="top" class="even"><td><tt>xs:gYearMonth</tt></td><td><a href="qvariant.html#Type-enum">QVariant::DateTime</a></td></tr>
230
 
<tr valign="top" class="odd"><td><tt>xs:gMonthDay</tt></td><td><a href="qvariant.html#Type-enum">QVariant::DateTime</a></td></tr>
231
 
<tr valign="top" class="even"><td><tt>xs:gDay</tt></td><td><a href="qvariant.html#Type-enum">QVariant::DateTime</a></td></tr>
232
 
<tr valign="top" class="odd"><td><tt>xs:gMonth</tt></td><td><a href="qvariant.html#Type-enum">QVariant::DateTime</a></td></tr>
233
 
<tr valign="top" class="even"><td><tt>xs:anyURI</tt></td><td><a href="qvariant.html#Type-enum">QVariant::Url</a></td></tr>
234
 
<tr valign="top" class="odd"><td><tt>xs:untypedAtomic</tt></td><td><a href="qvariant.html#Type-enum">QVariant::String</a></td></tr>
235
 
<tr valign="top" class="even"><td><tt>xs:ENTITY</tt></td><td><a href="qvariant.html#Type-enum">QVariant::String</a></td></tr>
236
 
<tr valign="top" class="odd"><td><tt>xs:date</tt></td><td><a href="qvariant.html#Type-enum">QVariant::DateTime</a></td></tr>
237
 
<tr valign="top" class="even"><td><tt>xs:dateTime</tt></td><td><a href="qvariant.html#Type-enum">QVariant::DateTime</a></td></tr>
238
 
<tr valign="top" class="odd"><td><tt>xs:time</tt></td><td>(see <a href="#xstime-not-mapped">No mapping for xs:time</a> below)</td></tr>
239
 
</table></p>
240
 
<a name="handling-qxmlnames"></a><a name="handling-qxmlnames"></a>
241
 
<h5>Handling QXmlNames</h5>
242
 
<p>If your XQuery can return atomic value items of type <tt>xs:QName</tt>, they will appear in your <a href="qxmlresultitems.html">QXmlResultItems</a> as instances of <a href="qxmlname.html">QXmlName</a>. Since the <a href="qvariant.html">QVariant</a> class does not support the <a href="qxmlname.html">QXmlName</a> class directly, extracting them from <a href="qxmlresultitems.html">QXmlResultItems</a> requires a bit of slight-of-hand using the <a href="qmetatype.html">Qt metatype system</a>. We must modify our example to use a couple of template functions, a friend of <a href="qmetatype.html">QMetaType</a> (qMetaTypeId&lt;T&gt;()) and a friend of <a href="qvariant.html">QVariant</a> (qVariantValue&lt;T&gt;()):</p>
243
 
<pre>     QFile xq(&quot;myquery.xq&quot;);
244
 
 
245
 
     QXmlQuery query;
246
 
     query.setQuery(&amp;xq, QUrl::fromLocalFile(xq.fileName()));
247
 
 
248
 
     QXmlResultItems result;
249
 
     query.evaluateTo(&amp;result);
250
 
     QXmlItem item(result.next());
251
 
     while (!item.isNull()) {
252
 
         if (item.isAtomicValue()) {
253
 
             QVariant v = item.toAtomicValue();
254
 
             switch (v.type()) {
255
 
                 case QVariant::LongLong:
256
 
                     <span class="comment">// xs:integer</span>
257
 
                     break;
258
 
                 case QVariant::String:
259
 
                     <span class="comment">// xs:string</span>
260
 
                     break;
261
 
                 default:
262
 
                     if (v.userType() == qMetaTypeId&lt;QXmlName&gt;()) {
263
 
                         QXmlName n = qVariantValue&lt;QXmlName&gt;(v);
264
 
                         <span class="comment">// process QXmlName n...</span>
265
 
                     }
266
 
                     else {
267
 
                         <span class="comment">// error</span>
268
 
                     }
269
 
                     break;
270
 
             }
271
 
         }
272
 
         else if (item.isNode()) {
273
 
             QXmlNodeModelIndex i = item.toNodeModelIndex();
274
 
             <span class="comment">// process node</span>
275
 
         }
276
 
         item = result.next();
277
 
     }</pre>
278
 
<p>To access the strings in a <a href="qxmlname.html">QXmlName</a> returned by an <a href="qxmlquery.html#evaluateTo">XQuery evaluation</a>, the <a href="qxmlname.html">QXmlName</a> must be accessed with the <a href="qxmlnamepool.html">name pool</a> from the instance of <a href="qxmlquery.html">QXmlQuery</a> that was used for the evaluation.</p>
279
 
<a name="xstime-not-mapped"></a><a name="no-mapping-for-xs-time"></a>
280
 
<h5>No mapping for xs:time</h5>
281
 
<p>An instance of <tt>xs:time</tt> can't be represented correctly as an instance of <a href="qvariant.html#Type-enum">QVariant::Time</a>, unless the <tt>xs:time</tt> is a UTC time. This is because xs:time has a zone offset (0 for UTC) in addition to the time value, which the <a href="qtime.html">QTime</a> in <a href="qvariant.html#Type-enum">QVariant::Time</a> does not have. This means that if an XQuery tries to return an atomic value of type <tt>xs:time</tt>, an invalid <a href="qvariant.html">QVariant</a> will be returned. A query can return an atomic value of type xs:time by either converting it to an <tt>xs:dateTime</tt> with an arbitrary date, or to an <tt>xs:string</tt>.</p>
282
 
<a name="using-xquery-with-non-xml-data"></a>
283
 
<h3>Using XQuery with Non-XML Data</h3>
284
 
<p>Although the XQuery language was designed for querying XML, with QtXmlPatterns one can use XQuery for querying any data that can be modeled to look like XML. Non-XML data is modeled to look like XML by loading it into a custom subclass of <a href="qabstractxmlnodemodel.html">QAbstractXmlNodeModel</a>, where it is then presented to the QtXmlPatterns XQuery engine via the same API the XQuery engine uses for querying XML.</p>
285
 
<p>When QtXmlPatterns loads and queries XML files and produces XML output, it can always load the XML data into its default XML node model, where it can be traversed efficiently. The XQuery below traverses the product orders found in the XML file <i>myOrders.xml</i> to find all the skin care product orders and output them ordered by shipping date.</p>
286
 
<pre> &lt;result&gt;
287
 
     &lt;para&gt;The following skin care products have shipped, ordered by shipping date(oldest first):&lt;/para&gt;
288
 
     {
289
 
         for $i in doc(&quot;myOrders.xml&quot;)/orders/order[@product = &quot;Acme Skin Care&quot;]
290
 
         order by xs:date($i/@shippingDate) descending
291
 
         return $i
292
 
     }
293
 
 &lt;/result&gt;</pre>
294
 
<p>QtXmlPatterns can be used out of the box to perform this query, provided <i>myOrders.xml</i> actually contains well-formed XML. It can be loaded directly into the default XML node model and traversed. But suppose we want QtXmlPatterns to perform queries on the hierarchical structure of the local file system. The default XML node model in QtXmlPatterns is not suitable for navigating the file system, because there is no XML file to load that contains a description of it. Such an XML file, if it existed, might look something like this:</p>
295
 
<pre> &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
296
 
 &lt;directory name=&quot;home&quot;&gt;
297
 
 
298
 
     &lt;file name=&quot;myNote.txt&quot; mimetype=&quot;text/plain&quot; size=&quot;8&quot; extension=&quot;txt&quot; uri=&quot;file:///home/frans/myNote.txt&quot;&gt;
299
 
         &lt;content asBase64Binary=&quot;TXkgTm90ZSE=&quot; asStringFromUTF-8=&quot;My Note!&quot;/&gt;
300
 
     &lt;/file&gt;
301
 
 
302
 
     &lt;directory name=&quot;src&quot;&gt;
303
 
         ...
304
 
     &lt;/directory&gt;
305
 
 
306
 
     ...
307
 
 
308
 
 &lt;/directory&gt;</pre>
309
 
<p>The <a href="xmlpatterns-filetree.html">File System Example</a> does exactly this.</p>
310
 
<p>There is no such file to load into the default XML node model, but one can write a subclass of <a href="qabstractxmlnodemodel.html">QAbstractXmlNodeModel</a> to represent the file system. This custom XML node model, once populated with all the directory and file descriptors obtained directly from the system, presents the complete file system hierarchy to the query engine via the same API used by the default XML node model to present the contents of an XML file. In other words, once the custom XML node model is populated, it presents the file system to the query engine as if a description of it had been loaded into the default XML node model from an XML file like the one shown above.</p>
311
 
<p>Now we can write an XQuery to find all the XML files and parse them to find the ones that don't contain well-formed XML.</p>
312
 
<pre> &lt;html&gt;
313
 
     &lt;body&gt;
314
 
         {
315
 
             $myRoot//file[@mimetype = 'text/xml' or @mimetype = 'application/xml']
316
 
             /
317
 
             (if(doc-available(@uri))
318
 
              then ()
319
 
              else &lt;p&gt;Failed to parse file {@uri}.&lt;/p&gt;)
320
 
         }
321
 
     &lt;/body&gt;
322
 
 &lt;/html&gt;</pre>
323
 
<p>Without QtXmlPatterns, there is no simple way to solve this kind of problem. You might do it by writing a C++ program to traverse the file system, sniff out all the XML files, and submit each one to an XML parser to test that it contains valid XML. The C++ code required to write that program will probably be more complex than the C++ code required to subclass <a href="qabstractxmlnodemodel.html">QAbstractXmlNodeModel</a>, but even if the two are comparable, your custom C++ program can be used only for that one task, while your custom XML node model can be used by any XQuery that must navigate the file system.</p>
324
 
<p>The general approach to using XQuery to perform queries on non-XML data has been a three step process. In the first step, the data is loaded into a non-XML data model. In the second step, the non-XML data model is serialized as XML and output to XML (text) files. In the final step, an XML tool loads the XML files into a second, XML data model, where the XQueries can be performed. The development cost of implementing this process is often high, and the three step system that results is inefficient because the two data models must be built and maintained separately.</p>
325
 
<p>With QtXmlPatterns, subclassing <a href="qabstractxmlnodemodel.html">QAbstractXmlNodeModel</a> eliminates the transformation required to convert the non-XML data model to the XML data model, because there is only ever one data model required. The non-XML data model presents the non-XML data to the query engine via the XML data model API. Also, since the query engine uses the API to access the <a href="qabstractxmlnodemodel.html">QAbstractXmlNodeModel</a>, the data model subclass can construct the elements, attributes and other data on demand, responding to the query's specific requests. This can greatly improve efficiency, because it means the entire model might not have to be built. For example, in the file system model above, it is not necessary to build an instance for a whole XML file representing the whole file system. Instead nodes are created on demand, which also likely is a small subset of the file system.</p>
326
 
<p>Examples of other places where XQuery could be used in QtXmlPatterns to query non-XML data:</p>
327
 
<ul>
328
 
<li>The internal representation for word processor documents</li>
329
 
<li>The set of dependencies for a software build system</li>
330
 
<li>The hierarchy (or graph) that links a set of HTML documents from a web crawler</li>
331
 
<li>The images and meta-data in an image collection</li>
332
 
<li>The set of D-Bus interfaces available in a system</li>
333
 
<li>A <a href="qobject.html">QObject</a> hierarchy, as seen in the <a href="xmlpatterns-qobjectxmlmodel.html">QObject XML Model example</a>.</li>
334
 
</ul>
335
 
<p>See the <a href="qabstractxmlnodemodel.html">QAbstractXmlNodeModel</a> documentation for information about how to implement custom XML node models.</p>
336
 
<a name="more-on-using-qtxmlpatterns-with-non-xml-data"></a>
337
 
<h3>More on using QtXmlPatterns with non-XML Data</h3>
338
 
<p>Subclassing <a href="qabstractxmlnodemodel.html">QAbstractXmlNodeModel</a> to let the query engine access non-XML data by the same API it uses for XML is the feature that enables QtXmlPatterns to query non-XML data with XQuery. It allows XQuery to be used as a mapping layer between different non-XML node models or between a non-XML node model and the built-in XML node model. Once the subclass(es) of <a href="qabstractxmlnodemodel.html">QAbstractXmlNodeModel</a> have been written, XQuery can be used to select a set of elements from one node model, transform the selected elements, and then write them out, either as XML using <a href="qxmlquery.html#evaluateTo">QXmlQuery::evaluateTo</a>() and <a href="qxmlserializer.html">QXmlSerializer</a>, or as some other format using a subclass of <a href="qabstractxmlreceiver.html">QAbstractXmlReceiver</a>.</p>
339
 
<p>Consider a word processor application that must import and export data in several different formats. Rather than writing a lot of C++ code to convert each input format to an intermediate form, and more C++ code to convert the intermediate form back to each output format, one can implement a solution based on QtXmlPatterns that uses simple XQueries to transform each XML or non-XML format (e.g&#x2e; MathFormula.xml below) to the intermediate form (e.g&#x2e; the DocumentRepresentation node model class below), and more simple XQueries to transform the intermediate form back to each XML or non-XML format.</p>
340
 
<p align="center"><img src="images/patternist-wordProcessor.png" /></p><p>Because CSV files are not XML, a subclass of <a href="qabstractxmlnodemodel.html">QAbstractXmlNodeModel</a> is used to present the CSV data to the XQuery engine as if it were XML. What are not shown are the subclasses of <a href="qabstractxmlreceiver.html">QAbstractXmlReceiver</a> that would then send the selected elements into the DocumentRepresentation node model, and the subclasses of <a href="qabstractxmlnodemodel.html">QAbstractXmlNodeModel</a> that would ultimately write the output files in each format.</p>
341
 
<a name="security-considerations"></a>
342
 
<h3>Security Considerations</h3>
343
 
<a name="code-injection"></a>
344
 
<h4>Code Injection</h4>
345
 
<p>XQuery is vulnerable to <a href="http://en.wikipedia.org/wiki/Code_injection">code injection attacks</a> in the same way as the SQL language. If an XQuery is constructed by concatenating strings, and the strings come from user input, the constructed XQuery could be malevolent. The best way to prevent code injection attacks is to not construct XQueries from user-written strings, but only accept user data input using <a href="qvariant.html">QVariant</a> and variable bindings. See <a href="qxmlquery.html#bindVariable">QXmlQuery::bindVariable</a>().</p>
346
 
<p>The articles <a href="http://www.ibm.com/developerworks/xml/library/x-xpathinjection.html">Avoid the dangers of XPath injection</a>, by Robi Sen and <a href="http://www.packetstormsecurity.org/papers/bypass/Blind_XPath_Injection_20040518.pdf">Blind XPath Injection</a>, by Amit Klein, discuss the XQuery code injection problem in more detail.</p>
347
 
<a name="denial-of-service-attacks"></a>
348
 
<h4>Denial of Service Attacks</h4>
349
 
<p>Applications using QtXmlPatterns are subject to the same limitations of software as other systems. Generally, these can not be checked. This means QtXmlPatterns does not prevent rogue queries from consuming too many resources. For example, a query could take too much time to execute or try to transfer too much data. A query could also do too much recursion, which could crash the system. XQueries can do these things accidentally, but they can also be done as deliberate denial of service attacks.</p>
350
 
<a name="features-and-conformance"></a>
351
 
<h3>Features and Conformance</h3>
352
 
<a name="xquery-1-0"></a>
353
 
<h4>XQuery 1.0</h4>
354
 
<p>QtXmlPatterns aims at being a <a href="http://www.w3.org/TR/xquery/#id-xquery-conformance">conformant XQuery processor</a>. It adheres to <a href="http://www.w3.org/TR/xquery/#id-minimal-conformance">Minimal Conformance</a> and supports the <a href="http://www.w3.org/TR/xquery/#id-serialization-feature">Serialization Feature</a> and the <a href="http://www.w3.org/TR/xquery/#id-full-axis-feature">Full Axis Feature</a>. QtXmlPatterns currently passes 97% of the tests in the <a href="http://www.w3.org/XML/Query/test-suite">XML Query Test Suite</a>. Areas where conformance may be questionable and where behavior may be changed in future releases include:</p>
355
 
<ul>
356
 
<li>Some corner cases involving namespaces and element constructors are incorrect.</li>
357
 
<li>XPath is a subset of XQuery and the implementation of QtXmlPatterns uses XPath 2.0 with XQuery 1.0&#x2e;</li>
358
 
</ul>
359
 
<p>The specifications discusses conformance further: <a href="http://www.w3.org/TR/xquery/">XQuery 1.0: An XML Query Language</a>. W3C's XQuery testing effort can be of interest as well, <a href="http://www.w3.org/XML/Query/test-suite/">XML Query Test Suite</a>.</p>
360
 
<p>Currently <tt>fn:collection()</tt> does not access any data set, and there is no API for providing data through the collection. As a result, evaluating <tt>fn:collection()</tt> returns the empty sequence. We intend to provide functionality for this in a future release of Qt.</p>
361
 
<p>Only queries encoded in UTF-8 are supported.</p>
362
 
<a name="xslt-2-0"></a>
363
 
<h4>XSLT 2.0</h4>
364
 
<p>Partial support for XSLT was introduced in Qt 4.5&#x2e; Future releases of QtXmlPatterns will aim to support these XSLT features:</p>
365
 
<ul>
366
 
<li>Basic XSLT 2.0 processor</li>
367
 
<li>Serialization feature</li>
368
 
<li>Backwards Compatibility feature</li>
369
 
</ul>
370
 
<p>For details, see <a href="http://www.w3.org/TR/xslt20/#conformance">XSL Transformations (XSLT) Version 2.0, 21 Conformance</a>.</p>
371
 
<p><b>Note:</b> In this release, XSLT support is considered experimental.</p>
372
 
<p>Unsupported or partially supported XSLT features are documented in the following table. The implementation of XSLT in Qt 4.5 can be seen as XSLT 1.0 but with the data model of XPath 2.0 and XSLT 2.0, and using the using the functionality of XPath 2.0 and its accompanying function library. When QtXmlPatterns encounters an unsupported or partially support feature, it will either report a syntax error or silently continue, unless otherwise noted in the table.</p>
373
 
<p>The implementation currently passes 42% of W3C's XSLT test suite, which focus on features introduced in XSLT 2.0&#x2e;</p>
374
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
375
 
<thead><tr valign="top" class="qt-style"><th>XSL Feature</th><th>Support Status</th></tr></thead>
376
 
<tr valign="top" class="odd"><td><tt>xsl:key</tt> and <tt>fn:key()</tt></td><td>not supported</td></tr>
377
 
<tr valign="top" class="even"><td><tt>xsl:include</tt></td><td>not supported</td></tr>
378
 
<tr valign="top" class="odd"><td><tt>xsl:import</tt></td><td>not supported</td></tr>
379
 
<tr valign="top" class="even"><td><tt>xsl:copy</tt></td><td>The <tt>copy-namespaces</tt> and <tt>inherit-namespaces</tt> attributes have no effect. For copied comments, attributes and processing instructions, the copy has the same node identity as the original.</td></tr>
380
 
<tr valign="top" class="odd"><td><tt>xsl:copy-of</tt></td><td>The <tt>copy-namespaces</tt> attribute has no effect.</td></tr>
381
 
<tr valign="top" class="even"><td><tt>fn:format-number()</tt></td><td>not supported</td></tr>
382
 
<tr valign="top" class="odd"><td><tt>xsl:message</tt></td><td>not supported</td></tr>
383
 
<tr valign="top" class="even"><td><tt>xsl:use-when</tt></td><td>not supported</td></tr>
384
 
<tr valign="top" class="odd"><td><tt>Tunnel</tt> Parameters</td><td>not supported</td></tr>
385
 
<tr valign="top" class="even"><td><tt>xsl:attribute-set</tt></td><td>not supported</td></tr>
386
 
<tr valign="top" class="odd"><td><tt>xsl:decimal-format</tt></td><td>not supported</td></tr>
387
 
<tr valign="top" class="even"><td><tt>xsl:fallback</tt></td><td>not supported</td></tr>
388
 
<tr valign="top" class="odd"><td><tt>xsl:apply-imports</tt></td><td>not supported</td></tr>
389
 
<tr valign="top" class="even"><td><tt>xsl:character-map</tt></td><td>not supported</td></tr>
390
 
<tr valign="top" class="odd"><td><tt>xsl:number</tt></td><td>not supported</td></tr>
391
 
<tr valign="top" class="even"><td><tt>xsl:namespace-alias</tt></td><td>not supported</td></tr>
392
 
<tr valign="top" class="odd"><td><tt>xsl:output</tt></td><td>not supported</td></tr>
393
 
<tr valign="top" class="even"><td><tt>xsl:output-character</tt></td><td>not supported</td></tr>
394
 
<tr valign="top" class="odd"><td><tt>xsl:preserve-space</tt></td><td>not supported</td></tr>
395
 
<tr valign="top" class="even"><td><tt>xsl:result-document</tt></td><td>not supported</td></tr>
396
 
<tr valign="top" class="odd"><td>Patterns</td><td>Complex patterns or patterns with predicates have issues.</td></tr>
397
 
<tr valign="top" class="even"><td><tt>2.0</tt> Compatibility Mode</td><td>Stylesheets are interpreted as XSLT 2.0 stylesheets, even if the <tt>version</tt> attribute is in the XSLT source is 1.0&#x2e; In other words, the version attribute is ignored.</td></tr>
398
 
<tr valign="top" class="odd"><td>Grouping</td><td><tt>fn:current-group()</tt>, <tt>fn:grouping-key()</tt> and <tt>xsl:for-each-group</tt>.</td></tr>
399
 
<tr valign="top" class="even"><td>Regexp elements</td><td><tt>xsl:analyze-string</tt>, <tt>xsl:matching-substring</tt>, <tt>xsl:non-matching-substring</tt>, and <tt>fn:regex-group()</tt></td></tr>
400
 
<tr valign="top" class="odd"><td>Date &amp; Time formatting</td><td><tt>fn:format-dateTime()</tt>, <tt>fn:format-date()</tt> and fn:format-time().</td></tr>
401
 
<tr valign="top" class="even"><td>XPath Conformance</td><td>Since XPath is a subset of XSLT, its issues are in affect too.</td></tr>
402
 
</table></p>
403
 
<p>The QtXmlPatterns implementation of the XPath Data Model does not include entities (due to <a href="qxmlstreamreader.html">QXmlStreamReader</a> not reporting them). This means that functions <tt>unparsed-entity-uri()</tt> and <tt>unparsed-entity-public-id()</tt> always return negatively.</p>
404
 
<a name="xpath-2-0"></a>
405
 
<h4>XPath 2.0</h4>
406
 
<p>Since XPath 2.0 is a subset of XQuery 1.0, XPath 2.0 is supported. Areas where conformance may be questionable and, consequently, where behavior may be changed in future releases include:</p>
407
 
<ul>
408
 
<li>Regular expression support is currently not conformant but follows Qt's <a href="qregexp.html">QRegExp</a> standard syntax.</li>
409
 
<li>Operators for <tt>xs:time</tt>, <tt>xs:date</tt>, and <tt>xs:dateTime</tt> are incomplete.</li>
410
 
<li>Formatting of very large or very small <tt>xs:double</tt>, <tt>xs:float</tt>, and <tt>xs:decimal</tt> values may be incorrect.</li>
411
 
</ul>
412
 
<a name="xml-id"></a>
413
 
<h4>xml:id</h4>
414
 
<p>Processing of XML files supports <tt>xml:id</tt>. This allows elements that have an attribute named <tt>xml:id</tt> to be looked up efficiently with the <tt>fn:id()</tt> function. See <a href="http://www.w3.org/TR/xml-id/">xml:id Version 1.0</a> for details.</p>
415
 
<a name="resource-loading"></a>
416
 
<h4>Resource Loading</h4>
417
 
<p>When QtXmlPatterns loads an XML resource, e.g&#x2e;, using the <tt>fn:doc()</tt> function, the following schemes are supported:</p>
418
 
<p><table align="center" cellpadding="2" cellspacing="1" border="0">
419
 
<thead><tr valign="top" class="qt-style"><th>Scheme Name</th><th>Description</th></tr></thead>
420
 
<tr valign="top" class="odd"><td><tt>file</tt></td><td>Local files.</td></tr>
421
 
<tr valign="top" class="even"><td><tt>data</tt></td><td>The bytes are encoded in the URI itself. e.g&#x2e;, <tt>data:application/xml,%3Ce%2F%3E</tt> is <tt>&lt;e/&gt;</tt>.</td></tr>
422
 
<tr valign="top" class="odd"><td><tt>ftp</tt></td><td>Resources retrieved via FTP.</td></tr>
423
 
<tr valign="top" class="even"><td><tt>http</tt></td><td>Resources retrieved via HTTP.</td></tr>
424
 
<tr valign="top" class="odd"><td><tt>https</tt></td><td>Resources retrieved via HTTPS. This will succeed if no SSL errors are encountered.</td></tr>
425
 
<tr valign="top" class="even"><td><tt>qrc</tt></td><td>Qt Resource files. Expressing it as an empty scheme, :/..&#x2e;, is not supported.</td></tr>
426
 
</table></p>
427
 
<a name="xml"></a>
428
 
<h4>XML</h4>
429
 
<p>XML 1.0 and XML Namespaces 1.0 are supported, as opposed to the 1.1 versions. When a strings is passed to a query as a <a href="qstring.html">QString</a>, the characters must be XML 1.0 characters. Otherwise, the behavior is undefined. This is not checked.</p>
430
 
<p>URIs are first passed to <a href="qabstracturiresolver.html">QAbstractUriResolver</a>. Check <a href="qxmlquery.html#setUriResolver">QXmlQuery::setUriResolver</a>() for possible rewrites.</p>
431
 
<p>
 
51
<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>
 
52
<a name="license-information"></a>
 
53
<h3>License Information</h3>
 
54
<p>The XML Schema implementation provided by this module contains the <tt>xml.xsd</tt> file (located in <tt>src/xmlpatterns/schema/schemas</tt>) which is licensed under the terms given below. This module is always built with XML Schema support enabled.</p>
 
55
<div style="padding: 0.5em; background: #e0e0e0; color: black"><p>W3C&copy; SOFTWARE NOTICE AND LICENSE</p>
 
56
<p>This license came from: http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231</p>
 
57
<p>This work (and included software, documentation such as READMEs, or other related items) is being provided by the copyright holders under the following license. By obtaining, using and/or copying this work, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions.</p>
 
58
<p>Permission to copy, modify, and distribute this software and its documentation, with or without modification, for any purpose and without fee or royalty is hereby granted, provided that you include the following on ALL copies of the software and documentation or portions thereof, including modifications:</p>
 
59
<p>1. The full text of this NOTICE in a location viewable to users of the redistributed or derivative work.<br /> 2. Any pre-existing intellectual property disclaimers, notices, or terms and conditions. If none exist, the W3C Software Short Notice should be included (hypertext is preferred, text is permitted) within the body of any redistributed or derivative code.<br /> 3. Notice of any changes or modifications to the files, including the date changes were made. (We recommend you provide URIs to the location from which the code is derived.)</p>
 
60
<p>THIS SOFTWARE AND DOCUMENTATION IS PROVIDED &quot;AS IS,&quot; AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.</p>
 
61
<p>COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.</p>
 
62
<p>The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the software without specific, written prior permission. Title to copyright in this software and any associated documentation will at all times remain with copyright holders.</p>
 
63
</div><p>
432
64
[Previous: <a href="qtxml.html">QtXml Module</a>]
433
 
[<a href="modules.html">Qt's Modules</a>]
 
65
[<a href="modules.html">All Qt Modules</a>]
434
66
[Next: <a href="phonon-module.html">Phonon Module</a>]
435
67
</p>
436
68
<p /><address><hr /><div align="center">
437
69
<table width="100%" cellspacing="0" border="0"><tr class="address">
438
 
<td width="30%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
439
 
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
440
 
<td width="30%" align="right"><div align="right">Qt 4.5.2</div></td>
441
 
</tr></table></div></address></body>
 
70
<td width="40%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
 
71
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
72
<td width="40%" align="right"><div align="right">Qt 4.6.0</div></td>
 
73
<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>
442
74
</html>