XML : Error validating/parsing xml file against xsd with lxml/objectify in Python

in Python/Django, I need to parse and objectify a file .xml according to a given XMLSchema made of three .xsd files referring each other:

schema3.xsd (referring schema1.xsd)

schema2.xsd (referring schema1.xsd)

schema1.xsd (referring schema2.xsd)

For this I'm using the following piece of code which I've already tested being succesfull when used with a couple of xml/xsd files (where .xsd is "standalone" without refering others .xsd):

  import lxml  import os.path  from lxml import etree, objectify  from lxml.etree import XMLSyntaxError    def xml_validator(request):        # define path of files      path_file_xml = '../myxmlfile.xml'      path_file_xsd = '../schema3.xsd'            # get file XML      xml_file = open(path_file_xml, 'r')      xml_string = xml_file.read()      xml_file.close()        # get XML Schema      doc = etree.parse(path_file_xsd)      schema = etree.XMLSchema(doc)        #define parser      parser = objectify.makeparser(schema=schema)      #parser = etree.XMLParser(sschema=schema)        # trasform XML file      root = objectify.fromstring(xml_string, parser)      test1 = root.tag        return render(request, 'risultati.html', {'risultato': test1})  

Unfortunately, I'm stucked with the following error that ii gout with the above multiple .xsd:

complex type 'ObjectType': The content model is not determinist.

Request Method: GET Request URL: http://127.0.0.1:8000/xml_validator

Django Version: 1.9.1 Exception Type: XMLSchemaParseError Exception

Value: complex type 'ObjectType': The content model is not determinist., line 80

Any idea about that ?

Thanks a lot in advance for any suggestion or useful tips to approach this problem...

cheers

No comments:

Post a Comment