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

Community
  • 1
  • 1
3biano
  • 21
  • 4
  • 1
    Please show a sample of _all_ the XSD documents that are involved, together with the XML file you are validating. More help: http://stackoverflow.com/help/mcve. – Mathias Müller Jan 17 '16 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... – 3biano Jan 20 '16 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.. – Mathias Müller Jan 20 '16 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 [mcve] **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 Mar 22 '16 at 14:30
  • Thank you Mogsdad, I'm now going to follow the rules you suggested... – 3biano Mar 22 '16 at 14:41
  • Dear @Mathias, I'm re-opening this post because I'm now allowed to include a sample of the files... Their code is listed on GitHub at the following link: https://github.com/perentix/lxml_multiple_xsd Thanks a lot in advance if someone has the chance to have a look on it... any kind of suggestion would be highly appreciated ! – 3biano Mar 22 '16 at 15:20
  • Linking to Github is not what we have asked of you. We have asked you to break down your code, throwing away all its length and complexities, and only keep the minimum that is necessary to reproduce the problem. See http://stackoverflow.com/help/mcve. For example, remove an import statement to disregard one of the XML schema documents and see whether the error is still there. Obviously, the type `ObjectType` is causing a problem, on line 80 - so why not keep this type and throw out everything which is unnecessary? – Mathias Müller Mar 22 '16 at 15:40

1 Answers1

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.

kimbert
  • 2,376
  • 1
  • 10
  • 20
  • 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... – 3biano Jan 20 '16 at 13:54
  • 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. – kimbert Jan 21 '16 at 14:57