2
votes

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 in such a way:

schema3.xsd (referring schema1.xsd)

schema2.xsd (referring schema1.xsd)

schema1.xsd (referring schema2.xsd)

xml schemas import

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)

    # 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 i got with the multiple .xsd described above:

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

Update 23/03/2016

Here (and in the following answers to the post, because it actually exceed the max number of characters for a post), a sample of the files to figure out the problem...

sample files on GitHub

1
Please show a sample of all the XSD documents that are involved, together with the XML file you are validating. More help: stackoverflow.com/help/mcve.Mathias Müller
Dear Mathias, thanks a lot for your reply... unfortunately I'm not allowed to post a sample of the files because they're owned by a third part that must keep them private for security reasons... To clarify a bit, I've just added to the post above a screenshot of the top part of the three files .xsd which shows how them import each other...3biano
We cannot help you if you cannot give enough information. We need enough information so that we can reproduce your problem. If the code is confidential, the only thing you can do is put together a small, artificial example that results in the same error. As I said: stackoverflow.com/help/mcve..Mathias Müller
Seems that you have too much code to fit in the question. No worries - here's how to deal with that. You should post a minimal reproducible example in the question itself. The larger body of code can be hosted (e.g. github, bitbucket, etc.), and linked to as a reference. The goal is to help you, but also to help future users - keeping your question self-contained and focused on the issue does both. Good luck!Mogsdad
Thank you Mogsdad, I'm now going to follow the rules you suggested...3biano

1 Answers

0
votes

My best guess would be that your XSD model does not obey the Unique Particle Attribution rule. I would rule that out before looking at anything else.