File: qxmlschemavalidator.html

package info (click to toggle)
python-qt4 4.9.3-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 34,432 kB
  • sloc: python: 34,126; cpp: 11,938; xml: 290; makefile: 223; php: 27
file content (209 lines) | stat: -rw-r--r-- 17,421 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
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QXmlSchemaValidator Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">&#160;&#160;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&#160;&#183; <a href="classes.html"><font color="#004faf">All Classes</font></a>&#160;&#183; <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QXmlSchemaValidator Class Reference<br /><sup><sup>[<a href="qtxmlpatterns.html">QtXmlPatterns</a> module]</sup></sup></h1><p>The QXmlSchemaValidator class validates XML instance documents
against a W3C XML Schema. <a href="#details">More...</a></p>

<h3>Methods</h3><ul><li><div class="fn" /><b><a href="qxmlschemavalidator.html#QXmlSchemaValidator">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qxmlschemavalidator.html#QXmlSchemaValidator-2">__init__</a></b> (<i>self</i>, QXmlSchema&#160;<i>schema</i>)</li><li><div class="fn" />QAbstractMessageHandler <b><a href="qxmlschemavalidator.html#messageHandler">messageHandler</a></b> (<i>self</i>)</li><li><div class="fn" />QXmlNamePool <b><a href="qxmlschemavalidator.html#namePool">namePool</a></b> (<i>self</i>)</li><li><div class="fn" />QNetworkAccessManager <b><a href="qxmlschemavalidator.html#networkAccessManager">networkAccessManager</a></b> (<i>self</i>)</li><li><div class="fn" />QXmlSchema <b><a href="qxmlschemavalidator.html#schema">schema</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qxmlschemavalidator.html#setMessageHandler">setMessageHandler</a></b> (<i>self</i>, QAbstractMessageHandler&#160;<i>handler</i>)</li><li><div class="fn" /><b><a href="qxmlschemavalidator.html#setNetworkAccessManager">setNetworkAccessManager</a></b> (<i>self</i>, QNetworkAccessManager&#160;<i>networkmanager</i>)</li><li><div class="fn" /><b><a href="qxmlschemavalidator.html#setSchema">setSchema</a></b> (<i>self</i>, QXmlSchema&#160;<i>schema</i>)</li><li><div class="fn" /><b><a href="qxmlschemavalidator.html#setUriResolver">setUriResolver</a></b> (<i>self</i>, QAbstractUriResolver&#160;<i>resolver</i>)</li><li><div class="fn" />QAbstractUriResolver <b><a href="qxmlschemavalidator.html#uriResolver">uriResolver</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qxmlschemavalidator.html#validate">validate</a></b> (<i>self</i>, QUrl&#160;<i>source</i>)</li><li><div class="fn" />bool <b><a href="qxmlschemavalidator.html#validate-2">validate</a></b> (<i>self</i>, QIODevice&#160;<i>source</i>, QUrl&#160;<i>documentUri</i>&#160;=&#160;QUrl())</li><li><div class="fn" />bool <b><a href="qxmlschemavalidator.html#validate-3">validate</a></b> (<i>self</i>, QByteArray&#160;<i>data</i>, QUrl&#160;<i>documentUri</i>&#160;=&#160;QUrl())</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QXmlSchemaValidator class validates XML instance documents
against a W3C XML Schema.</p>
<p>The QXmlSchemaValidator class loads, parses an XML instance
document and validates it against a W3C XML Schema that has been
compiled with <a href="qxmlschema.html">QXmlSchema</a>.</p>
<p>The following example shows how to load a XML Schema from a
local file, check whether it is a valid schema document and use it
for validation of an XML instance document:</p>
<pre class="cpp">
     <span class="type"><a href="qurl.html">QUrl</a></span> schemaUrl(<span class="string">"file:///home/user/schema.xsd"</span>);

     <span class="type"><a href="qxmlschema.html">QXmlSchema</a></span> schema;
     schema<span class="operator">.</span>load(schemaUrl);

     <span class="keyword">if</span> (schema<span class="operator">.</span>isValid()) {
         <span class="type"><a href="qfile.html">QFile</a></span> file(<span class="string">"test.xml"</span>);
         file<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly);

         <span class="type">QXmlSchemaValidator</span> validator(schema);
         <span class="keyword">if</span> (validator<span class="operator">.</span>validate(<span class="operator">&amp;</span>file<span class="operator">,</span> <span class="type"><a href="qurl.html">QUrl</a></span><span class="operator">.</span>fromLocalFile(file<span class="operator">.</span>fileName())))
             <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"instance document is valid"</span>;
         <span class="keyword">else</span>
             <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"instance document is invalid"</span>;
     }
</pre>
<a id="xml-schema-version" name="xml-schema-version" />
<h3>XML Schema Version</h3>
<p>This class implements schema validation according to the
<a href="http://www.w3.org/XML/Schema">XML Schema</a> 1.0
specification.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QXmlSchemaValidator" />QXmlSchemaValidator.__init__ (<i>self</i>)</h3><p>Constructs a schema validator. The schema used for validation
must be referenced in the XML instance document via the
<tt>xsi:schemaLocation</tt> or
<tt>xsi:noNamespaceSchemaLocation</tt> attribute.</p>


<h3 class="fn"><a name="QXmlSchemaValidator-2" />QXmlSchemaValidator.__init__ (<i>self</i>, <a href="qxmlschema.html">QXmlSchema</a>&#160;<i>schema</i>)</h3><p>Constructs a schema validator that will use <i>schema</i> for
validation. If an empty <a href="qxmlschema.html">QXmlSchema</a>
schema is passed to the validator, the schema used for validation
must be referenced in the XML instance document via the
<tt>xsi:schemaLocation</tt> or
<tt>xsi:noNamespaceSchemaLocation</tt> attribute.</p>


<h3 class="fn"><a name="messageHandler" /><a href="qabstractmessagehandler.html">QAbstractMessageHandler</a> QXmlSchemaValidator.messageHandler (<i>self</i>)</h3><p>Returns the message handler that handles parsing and validation
messages for this <a href="qxmlschemavalidator.html">QXmlSchemaValidator</a>.</p>
<p><b>See also</b> <a href="qxmlschemavalidator.html#setMessageHandler">setMessageHandler</a>().</p>


<h3 class="fn"><a name="namePool" /><a href="qxmlnamepool.html">QXmlNamePool</a> QXmlSchemaValidator.namePool (<i>self</i>)</h3><p>Returns the name pool used by this <a href="qxmlschemavalidator.html">QXmlSchemaValidator</a> for constructing
<a href="qxmlname.html">names</a>. There is no setter for the name
pool, because mixing name pools causes errors due to name
confusion.</p>


<h3 class="fn"><a name="networkAccessManager" /><a href="qnetworkaccessmanager.html">QNetworkAccessManager</a> QXmlSchemaValidator.networkAccessManager (<i>self</i>)</h3><p>Returns the network manager, or 0 if it has not been set.</p>
<p><b>See also</b> <a href="qxmlschemavalidator.html#setNetworkAccessManager">setNetworkAccessManager</a>().</p>


<h3 class="fn"><a name="schema" /><a href="qxmlschema.html">QXmlSchema</a> QXmlSchemaValidator.schema (<i>self</i>)</h3><p>Returns the schema that is used for validation.</p>
<p><b>See also</b> <a href="qxmlschemavalidator.html#setSchema">setSchema</a>().</p>


<h3 class="fn"><a name="setMessageHandler" />QXmlSchemaValidator.setMessageHandler (<i>self</i>, <a href="qabstractmessagehandler.html">QAbstractMessageHandler</a>&#160;<i>handler</i>)</h3><p>Changes the <a href="qabstractmessagehandler.html">message
handler</a> for this <a href="qxmlschemavalidator.html">QXmlSchemaValidator</a> to
<i>handler</i>. The schema validator sends all parsing and
validation messages to this message handler. <a href="qxmlschemavalidator.html">QXmlSchemaValidator</a> does not take
ownership of <i>handler</i>.</p>
<p>Normally, the default message handler is sufficient. It writes
compile and validation messages to <i>stderr</i>. The default
message handler includes color codes if <i>stderr</i> can render
colors.</p>
<p>When <a href="qxmlschemavalidator.html">QXmlSchemaValidator</a>
calls <a href="qabstractmessagehandler.html#message">QAbstractMessageHandler.message</a>(),
the arguments are as follows:</p>
<table class="generic">
<thead>
<tr class="qt-style">
<th>message() argument</th>
<th>Semantics</th>
</tr>
</thead>
<tr class="odd" valign="top">
<td><a href="qtcore.html#QtMsgType-enum">QtMsgType</a> type</td>
<td>Only <a href="qtcore.html#QtMsgType-enum">QtWarningMsg</a>
and <a href="qtcore.html#QtMsgType-enum">QtFatalMsg</a> are used.
The former identifies a warning, while the latter identifies an
error.</td>
</tr>
<tr class="even" valign="top">
<td>const <a href="qstring.html">QString</a> &amp; description</td>
<td>An XHTML document which is the actual message. It is translated
into the current language.</td>
</tr>
<tr class="odd" valign="top">
<td>const <a href="qurl.html">QUrl</a> &amp;identifier</td>
<td>Identifies the error with a URI, where the fragment is the
error code, and the rest of the URI is the error namespace.</td>
</tr>
<tr class="even" valign="top">
<td>const <a href="qsourcelocation.html">QSourceLocation</a> &amp;
sourceLocation</td>
<td>Identifies where the error occurred.</td>
</tr>
</table>
<p><b>See also</b> <a href="qxmlschemavalidator.html#messageHandler">messageHandler</a>().</p>


<h3 class="fn"><a name="setNetworkAccessManager" />QXmlSchemaValidator.setNetworkAccessManager (<i>self</i>, <a href="qnetworkaccessmanager.html">QNetworkAccessManager</a>&#160;<i>networkmanager</i>)</h3><p>Sets the network manager to <i>manager</i>. <a href="qxmlschemavalidator.html">QXmlSchemaValidator</a> does not take
ownership of <i>manager</i>.</p>
<p><b>See also</b> <a href="qxmlschemavalidator.html#networkAccessManager">networkAccessManager</a>().</p>


<h3 class="fn"><a name="setSchema" />QXmlSchemaValidator.setSchema (<i>self</i>, <a href="qxmlschema.html">QXmlSchema</a>&#160;<i>schema</i>)</h3><p>Sets the <i>schema</i> that shall be used for further
validation. If the schema is empty, the schema used for validation
must be referenced in the XML instance document via the
<tt>xsi:schemaLocation</tt> or
<tt>xsi:noNamespaceSchemaLocation</tt> attribute.</p>
<p><b>See also</b> <a href="qxmlschemavalidator.html#schema">schema</a>().</p>


<h3 class="fn"><a name="setUriResolver" />QXmlSchemaValidator.setUriResolver (<i>self</i>, <a href="qabstracturiresolver.html">QAbstractUriResolver</a>&#160;<i>resolver</i>)</h3><p>Sets the URI resolver to <i>resolver</i>. <a href="qxmlschemavalidator.html">QXmlSchemaValidator</a> does not take
ownership of <i>resolver</i>.</p>
<p><b>See also</b> <a href="qxmlschemavalidator.html#uriResolver">uriResolver</a>().</p>


<h3 class="fn"><a name="uriResolver" /><a href="qabstracturiresolver.html">QAbstractUriResolver</a> QXmlSchemaValidator.uriResolver (<i>self</i>)</h3><p>Returns the schema's URI resolver. If no URI resolver has been
set, <a href="qtxmlpatterns.html">QtXmlPatterns</a> will use the
URIs in instance documents as they are.</p>
<p>The URI resolver provides a level of abstraction, or
<i>polymorphic URIs</i>. A resolver can rewrite <i>logical</i> URIs
to physical ones, or it can translate obsolete or invalid URIs to
valid ones.</p>
<p>When <a href="qtxmlpatterns.html">QtXmlPatterns</a> calls
<a href="qabstracturiresolver.html#resolve">QAbstractUriResolver.resolve</a>()
the absolute URI is the URI mandated by the schema specification,
and the relative URI is the URI specified by the user.</p>
<p><b>See also</b> <a href="qxmlschemavalidator.html#setUriResolver">setUriResolver</a>().</p>


<h3 class="fn"><a name="validate" />bool QXmlSchemaValidator.validate (<i>self</i>, <a href="qurl.html">QUrl</a>&#160;<i>source</i>)</h3><p>Validates the XML instance document read from <i>source</i>
against the schema.</p>
<p>Returns <tt>true</tt> if the XML instance document is valid
according to the schema, <tt>false</tt> otherwise.</p>
<p>Example:</p>
<pre class="cpp">
     <span class="keyword">const</span> <span class="type"><a href="qxmlschema.html">QXmlSchema</a></span> schema <span class="operator">=</span> getSchema();

     <span class="keyword">const</span> <span class="type"><a href="qurl.html">QUrl</a></span> url(<span class="string">"http://www.schema-example.org/test.xml"</span>);

     <span class="type"><a href="qxmlschemavalidator.html">QXmlSchemaValidator</a></span> validator(schema);
     <span class="keyword">if</span> (validator<span class="operator">.</span>validate(url))
         <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"instance document is valid"</span>;
     <span class="keyword">else</span>
         <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"instance document is invalid"</span>;
</pre>


<h3 class="fn"><a name="validate-2" />bool QXmlSchemaValidator.validate (<i>self</i>, <a href="qiodevice.html">QIODevice</a>&#160;<i>source</i>, <a href="qurl.html">QUrl</a>&#160;<i>documentUri</i>&#160;=&#160;QUrl())</h3><p>Validates the XML instance document read from <i>source</i> with
the given <i>documentUri</i> against the schema.</p>
<p>Returns <tt>true</tt> if the XML instance document is valid
according to the schema, <tt>false</tt> otherwise.</p>
<p>Example:</p>
<pre class="cpp">
     <span class="keyword">const</span> <span class="type"><a href="qxmlschema.html">QXmlSchema</a></span> schema <span class="operator">=</span> getSchema();

     <span class="type"><a href="qfile.html">QFile</a></span> file(<span class="string">"test.xml"</span>);
     file<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly);

     <span class="type"><a href="qxmlschemavalidator.html">QXmlSchemaValidator</a></span> validator(schema);
     <span class="keyword">if</span> (validator<span class="operator">.</span>validate(<span class="operator">&amp;</span>file<span class="operator">,</span> <span class="type"><a href="qurl.html">QUrl</a></span><span class="operator">.</span>fromLocalFile(file<span class="operator">.</span>fileName())))
         <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"instance document is valid"</span>;
     <span class="keyword">else</span>
         <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"instance document is invalid"</span>;
</pre>


<h3 class="fn"><a name="validate-3" />bool QXmlSchemaValidator.validate (<i>self</i>, <a href="qbytearray.html">QByteArray</a>&#160;<i>data</i>, <a href="qurl.html">QUrl</a>&#160;<i>documentUri</i>&#160;=&#160;QUrl())</h3><p>Validates the XML instance document read from <i>data</i> with
the given <i>documentUri</i> against the schema.</p>
<p>Returns <tt>true</tt> if the XML instance document is valid
according to the schema, <tt>false</tt> otherwise.</p>
<p>Example:</p>
<pre class="cpp">
     <span class="keyword">const</span> <span class="type"><a href="qxmlschema.html">QXmlSchema</a></span> schema <span class="operator">=</span> getSchema();

     <span class="type"><a href="qbytearray.html">QByteArray</a></span> data(<span class="string">"&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;"</span>
                     <span class="string">"&lt;test&gt;&lt;/test&gt;"</span>);

     <span class="type"><a href="qbuffer.html">QBuffer</a></span> buffer(<span class="operator">&amp;</span>data);
     buffer<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly);

     <span class="type"><a href="qxmlschemavalidator.html">QXmlSchemaValidator</a></span> validator(schema);
     <span class="keyword">if</span> (validator<span class="operator">.</span>validate(<span class="operator">&amp;</span>buffer))
         <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"instance document is valid"</span>;
     <span class="keyword">else</span>
         <a href="qtcore.html#qDebug">qDebug</a>() <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="string">"instance document is invalid"</span>;
</pre>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt&#160;4.9.3 for X11</td><td align="center" width="50%">Copyright &#169; <a href="http://www.riverbankcomputing.com">Riverbank&#160;Computing&#160;Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2012</td><td align="right" width="25%">Qt&#160;4.8.2</td></tr></table></div></address></body></html>