lxml and schema validation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hrishy

    lxml and schema validation

    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=et ree.parse("My.x sd")
    xmlschema=etree .XMLSchema(xmls chemadoc)
    xmldoc=etree.pa rse("My.XML")
    xmlschema.asser tValid(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 notstope at the first failure .
    my question would be how do i do that in python ?

    regards
    Hrishy



  • Stefan Behnel

    #2
    Re: lxml and schema validation

    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=et ree.parse("My.x sd")
    xmlschema=etree .XMLSchema(xmls chemadoc)
    Includes/Imports will be resolved at this point.

    xmldoc=etree.pa rse("My.XML")
    xmlschema.asser tValid(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

    Comment

    Working...