lxml and schema validation

H

hrishy

Hi

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)
xmldoc=etree.parse("My.XML")
xmlschema.assertValid(xmldoc)

will my program validate against My.xsd and My1.xsd both ?

I also would like my program to continue validation against the xsd and not stope at the first failure .
my question would be how do i do that in python ?

regards
Hrishy
 
S

Stefan Behnel

hrishy said:
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.

Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top