lxml and schema validation

Stefan Behnel stefan_ml at behnel.de
Fri Oct 3 18:11:12 CEST 2008

hrishy wrote:
> I am validating a xmlfile against a xsd (My.xsd) but i notice that the xsd has a include which includes another xsd (My1.xsd)
> I have written a simple program that to validate this
> from lxml import etree
> xmlschemadoc=etree.parse("My.xsd")
> xmlschema=etree.XMLSchema(xmlschemadoc)

Includes/Imports will be resolved at this point.

> xmldoc=etree.parse("My.XML")
> xmlschema.assertValid(xmldoc)
> will my program validate against My.xsd and My1.xsd both ?

It will be validated against My.xsd, which (as you said), includes My1.xsd.
So, yes, both schemas will participate in the validation.

> I also would like my program to continue validation against the xsd and not stope at the first failure.

You want to get a list of all validation errors, instead of bailing out after
the first failure, right? libxml2 doesn't support that. All you get is the
list of errors in the error log of the validator, but when libxml2 decides to
bail out from the validation, that's it.


More information about the Python-list mailing list