1 <?xml version="1.0" encoding="ascii"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6 <title>lxml.etree.Schematron</title>
7 <link rel="stylesheet" href="epydoc.css" type="text/css" />
8 <script type="text/javascript" src="epydoc.js"></script>
11 <body bgcolor="white" text="black" link="blue" vlink="#204080"
13 <!-- ==================== NAVIGATION BAR ==================== -->
14 <table class="navbar" border="0" width="100%" cellpadding="0"
15 bgcolor="#a0c0ff" cellspacing="0">
18 <th> <a
19 href="lxml-module.html">Home</a> </th>
22 <th> <a
23 href="module-tree.html">Trees</a> </th>
26 <th> <a
27 href="identifier-index.html">Indices</a> </th>
30 <th> <a
31 href="help.html">Help</a> </th>
33 <!-- Project homepage -->
34 <th class="navbar" align="right" width="100%">
35 <table border="0" cellpadding="0" cellspacing="0">
36 <tr><th class="navbar" align="center"
37 ><a class="navbar" target="_top" href="/">lxml API</a></th>
41 <table width="100%" cellpadding="0" cellspacing="0">
44 <span class="breadcrumbs">
45 <a href="lxml-module.html">Package lxml</a> ::
46 <a href="lxml.etree-module.html">Module etree</a> ::
51 <table cellpadding="0" cellspacing="0">
52 <!-- hide/show private -->
53 <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
54 onclick="toggle_private();">hide private</a>]</span></td></tr>
55 <tr><td align="right"><span class="options"
56 >[<a href="frames.html" target="_top">frames</a
57 >] | <a href="lxml.etree.Schematron-class.html"
58 target="_top">no frames</a>]</span></td></tr>
63 <!-- ==================== CLASS DESCRIPTION ==================== -->
64 <h1 class="epydoc">Class Schematron</h1><p class="nomargin-top"></p>
65 <pre class="base-tree">
68 <a href="lxml.etree._Validator-class.html" onclick="show_private();">_Validator</a> --+
70 <strong class="uidshort">Schematron</strong>
74 <p>Schematron(self, etree=None, file=None)
75 A Schematron validator.</p>
76 <p>Pass a root Element or an ElementTree to turn it into a validator.
77 Alternatively, pass a filename as keyword argument 'file' to parse from
79 <p>Schematron is a less well known, but very powerful schema language. The main
80 idea is to use the capabilities of XPath to put restrictions on the structure
81 and the content of XML documents. Here is a simple example:</p>
82 <pre class="rst-literal-block">
83 >>> schematron = etree.Schematron(etree.XML('''
84 ... <schema xmlns="http://www.ascc.net/xml/schematron" >
85 ... <pattern name="id is the only permited attribute name">
86 ... <rule context="*">
87 ... <report test="@*[not(name()='id')]">Attribute
88 ... <name path="@*[not(name()='id')]"/> is forbidden<name/>
95 >>> xml = etree.XML('''
96 ... <AAA name="aaa">
97 ... <BBB id="bbb"/>
98 ... <CCC color="ccc"/>
102 >>> schematron.validate(xml)
105 >>> xml = etree.XML('''
106 ... <AAA id="aaa">
107 ... <BBB id="bbb"/>
112 >>> schematron.validate(xml)
115 <p>Schematron was added to libxml2 in version 2.6.21. Before version 2.6.32,
116 however, Schematron lacked support for error reporting other than to stderr.
117 This version is therefore required to retrieve validation warnings and
120 <!-- ==================== INSTANCE METHODS ==================== -->
121 <a name="section-InstanceMethods"></a>
122 <table class="summary" border="1" cellpadding="3"
123 cellspacing="0" width="100%" bgcolor="white">
124 <tr bgcolor="#70b0f0" class="table-header">
125 <td colspan="2" class="table-header">
126 <table border="0" cellpadding="0" cellspacing="0" width="100%">
128 <td align="left"><span class="table-header">Instance Methods</span></td>
129 <td align="right" valign="top"
130 ><span class="options">[<a href="#section-InstanceMethods"
131 class="privatelink" onclick="toggle_private();"
132 >hide private</a>]</span></td>
138 <td width="15%" align="right" valign="top" class="summary">
139 <span class="summary-type"> </span>
140 </td><td class="summary">
141 <table width="100%" cellpadding="0" cellspacing="0" border="0">
143 <td><span class="summary-sig"><a href="lxml.etree.Schematron-class.html#__call__" class="summary-sig-name">__call__</a>(<span class="summary-sig-arg">self</span>,
144 <span class="summary-sig-arg">etree</span>)</span><br />
145 Validate doc using Schematron.</td>
146 <td align="right" valign="top">
156 <td width="15%" align="right" valign="top" class="summary">
157 <span class="summary-type"> </span>
158 </td><td class="summary">
159 <table width="100%" cellpadding="0" cellspacing="0" border="0">
161 <td><span class="summary-sig"><a href="lxml.etree.Schematron-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">self</span>,
162 <span class="summary-sig-arg">etree</span>=<span class="summary-sig-default">None</span>,
163 <span class="summary-sig-arg">file</span>=<span class="summary-sig-default">None</span>)</span><br />
164 x.__init__(...) initializes x; see help(type(x)) for signature</td>
165 <td align="right" valign="top">
175 <td width="15%" align="right" valign="top" class="summary">
176 <span class="summary-type">a new object with type S, a subtype of T</span>
177 </td><td class="summary">
178 <table width="100%" cellpadding="0" cellspacing="0" border="0">
180 <td><span class="summary-sig"><a href="lxml.etree.Schematron-class.html#__new__" class="summary-sig-name">__new__</a>(<span class="summary-sig-arg">T</span>,
181 <span class="summary-sig-arg">S</span>,
182 <span class="summary-sig-arg">...</span>)</span></td>
183 <td align="right" valign="top">
193 <td colspan="2" class="summary">
194 <p class="indent-wrapped-lines"><b>Inherited from <code><a href="lxml.etree._Validator-class.html" onclick="show_private();">_Validator</a></code></b>:
195 <code><a href="lxml.etree._Validator-class.html#assertValid">assertValid</a></code>,
196 <code><a href="lxml.etree._Validator-class.html#assert_">assert_</a></code>,
197 <code><a href="lxml.etree._Validator-class.html#validate">validate</a></code>
199 <div class="private"> <p class="indent-wrapped-lines"><b>Inherited from <code><a href="lxml.etree._Validator-class.html" onclick="show_private();">_Validator</a></code></b> (private):
200 <code><a href="lxml.etree._Validator-class.html#_append_log_message" onclick="show_private();">_append_log_message</a></code>,
201 <code><a href="lxml.etree._Validator-class.html#_clear_error_log" onclick="show_private();">_clear_error_log</a></code>
203 <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
204 <code>__delattr__</code>,
205 <code>__format__</code>,
206 <code>__getattribute__</code>,
207 <code>__hash__</code>,
208 <code>__reduce__</code>,
209 <code>__reduce_ex__</code>,
210 <code>__repr__</code>,
211 <code>__setattr__</code>,
212 <code>__sizeof__</code>,
213 <code>__str__</code>,
214 <code>__subclasshook__</code>
219 <!-- ==================== PROPERTIES ==================== -->
220 <a name="section-Properties"></a>
221 <table class="summary" border="1" cellpadding="3"
222 cellspacing="0" width="100%" bgcolor="white">
223 <tr bgcolor="#70b0f0" class="table-header">
224 <td colspan="2" class="table-header">
225 <table border="0" cellpadding="0" cellspacing="0" width="100%">
227 <td align="left"><span class="table-header">Properties</span></td>
228 <td align="right" valign="top"
229 ><span class="options">[<a href="#section-Properties"
230 class="privatelink" onclick="toggle_private();"
231 >hide private</a>]</span></td>
237 <td colspan="2" class="summary">
238 <p class="indent-wrapped-lines"><b>Inherited from <code><a href="lxml.etree._Validator-class.html" onclick="show_private();">_Validator</a></code></b>:
239 <code><a href="lxml.etree._Validator-class.html#error_log">error_log</a></code>
241 <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>:
242 <code>__class__</code>
247 <!-- ==================== METHOD DETAILS ==================== -->
248 <a name="section-MethodDetails"></a>
249 <table class="details" border="1" cellpadding="3"
250 cellspacing="0" width="100%" bgcolor="white">
251 <tr bgcolor="#70b0f0" class="table-header">
252 <td colspan="2" class="table-header">
253 <table border="0" cellpadding="0" cellspacing="0" width="100%">
255 <td align="left"><span class="table-header">Method Details</span></td>
256 <td align="right" valign="top"
257 ><span class="options">[<a href="#section-MethodDetails"
258 class="privatelink" onclick="toggle_private();"
259 >hide private</a>]</span></td>
265 <a name="__call__"></a>
267 <table class="details" border="1" cellpadding="3"
268 cellspacing="0" width="100%" bgcolor="white">
270 <table width="100%" cellpadding="0" cellspacing="0" border="0">
271 <tr valign="top"><td>
272 <h3 class="epydoc"><span class="sig"><span class="sig-name">__call__</span>(<span class="sig-arg">self</span>,
273 <span class="sig-arg">etree</span>)</span>
274 <br /><em class="fname">(Call operator)</em>
276 </td><td align="right" valign="top"
281 <p>Validate doc using Schematron.</p>
282 <p>Returns true if document is valid, false if not.</p>
287 <a name="__init__"></a>
289 <table class="details" border="1" cellpadding="3"
290 cellspacing="0" width="100%" bgcolor="white">
292 <table width="100%" cellpadding="0" cellspacing="0" border="0">
293 <tr valign="top"><td>
294 <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">self</span>,
295 <span class="sig-arg">etree</span>=<span class="sig-default">None</span>,
296 <span class="sig-arg">file</span>=<span class="sig-default">None</span>)</span>
297 <br /><em class="fname">(Constructor)</em>
299 </td><td align="right" valign="top"
304 x.__init__(...) initializes x; see help(type(x)) for signature
312 <a name="__new__"></a>
314 <table class="details" border="1" cellpadding="3"
315 cellspacing="0" width="100%" bgcolor="white">
317 <table width="100%" cellpadding="0" cellspacing="0" border="0">
318 <tr valign="top"><td>
319 <h3 class="epydoc"><span class="sig"><span class="sig-name">__new__</span>(<span class="sig-arg">T</span>,
320 <span class="sig-arg">S</span>,
321 <span class="sig-arg">...</span>)</span>
323 </td><td align="right" valign="top"
330 <dt>Returns: a new object with type S, a subtype of T</dt>
338 <!-- ==================== NAVIGATION BAR ==================== -->
339 <table class="navbar" border="0" width="100%" cellpadding="0"
340 bgcolor="#a0c0ff" cellspacing="0">
343 <th> <a
344 href="lxml-module.html">Home</a> </th>
347 <th> <a
348 href="module-tree.html">Trees</a> </th>
351 <th> <a
352 href="identifier-index.html">Indices</a> </th>
355 <th> <a
356 href="help.html">Help</a> </th>
358 <!-- Project homepage -->
359 <th class="navbar" align="right" width="100%">
360 <table border="0" cellpadding="0" cellspacing="0">
361 <tr><th class="navbar" align="center"
362 ><a class="navbar" target="_top" href="/">lxml API</a></th>
366 <table border="0" cellpadding="0" cellspacing="0" width="100%%">
368 <td align="left" class="footer">
369 Generated by Epydoc 3.0.1 on Tue Jul 31 10:14:18 2012
371 <td align="right" class="footer">
372 <a target="mainFrame" href="http://epydoc.sourceforge.net"
373 >http://epydoc.sourceforge.net</a>
378 <script type="text/javascript">
380 // Private objects are initially displayed (because if
381 // javascript is turned off then we want them to be
382 // visible); but by default, we want to hide them. So hide
383 // them unless we have a cookie that says to show them.