2

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

7
  • 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. Commented Jan 17, 2016 at 19:33
  • 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... Commented Jan 20, 2016 at 13:53
  • 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.. Commented Jan 20, 2016 at 13:57
  • 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! Commented Mar 22, 2016 at 14:30
  • Thank you Mogsdad, I'm now going to follow the rules you suggested... Commented Mar 22, 2016 at 14:41

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Dear Kimbert, thanks a lot for your tip... I've checked your link and I can confirm that my XSD model doesn't include fragments of that types phroibited according to UPA rule...
Are you quite sure that your content model is deterministic? This is not a question of whether your XSD looks like one of the examples. You have to look carefully at line 80 of your XSD, and satisfy yourself that you understand what the XSD validator is complaining about. Then you can decide whether the XSD validator has a bug, or your XSD is breaking the rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.