Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomatic XSD validation
    text
    copied!<p>According to the lxml documentation "The DTD is retrieved automatically based on the DOCTYPE of the parsed document. All you have to do is use a parser that has DTD validation enabled."</p> <p><a href="http://lxml.de/validation.html#validation-at-parse-time" rel="noreferrer">http://lxml.de/validation.html#validation-at-parse-time</a></p> <p>However, if you want to validate against an XML schema, you need to explicitly reference one.</p> <p>I am wondering why this is and would like to know if there is a library or function that can do this. Or even an explanation of how to make this happen myself. The problem is there seems to be many ways to reference an XSD and I need to support all of them.</p> <p>Validation is not the issue. The issue is how to determine the schemas to validate against. Ideally this would handle inline schemas as well.</p> <p><strong>Update:</strong></p> <p>Here is an example.</p> <p>simpletest.xsd:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"&gt; &lt;xs:element name="name" type="xs:string"/&gt; &lt;/xs:schema&gt; </code></pre> <p>simpletest.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;name xmlns="http://www.example.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org simpletest.xsd"&gt;foo&lt;/name&gt; </code></pre> <p>I would like to do something like the following:</p> <pre><code>&gt;&gt;&gt; parser = etree.XMLParser(xsd_validation=True) &gt;&gt;&gt; tree = etree.parse("simpletest.xml", parser) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload