Problem with order of elements in sequence

  • Indrek

    Indrek - 2013-07-07


    I just started to use Pyxb and generally I am happy with the results. BUT there is one thing which may be a bug (or missing functionality) or I can not understand existing functionality and failed to use it.

    Lets presume that we have following definition in XSD file:

    <xsd:element name="M">
          <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element ref="TA"/>
            <xsd:element ref="TB"/>
            <xsd:element ref="TC"/>

    According to this definition we can have following XML data:


    In this case I am interested that the order of elements between M-tags is available in content model ( do I understand correctly that content model is a data set what I get after parsing given XML string? ). Unfortunately I did not found possibility to extract from content model the original order of elements in input data. There was only map of element types {list_of_TA, list_of_TB, list_of_TC} and for each type exists a list of instances without any information about their original position in the sequence.

    So, have I missed something or this kind of ordering info is lost in the process?

  • Peter A. Bigot

    Peter A. Bigot - 2013-07-07

    There is some information on this in the online documentation. The short answer, though, is that PyXB is primarily concerned with preserving the order that is specified in the schema. If the schema allows arbitrary order of elements as in the choice group, PyXB has some facilities that support reconstructing document order, but does not treat this as a common requirement. It was only added to properly support mixed content, which is unusual in most of the structured data use cases PyXB handles.

    What content model means in PyXB is also in the documentation and I wouldn't want to try to paraphrase it before I've woken up more. Order of information extracted from a document is part of the binding model. (I notice a few errors in that page due to recent changes, so read it carefully and trust the description in the user reference page as being more accurate.)

    Last edit: Peter A. Bigot 2013-07-07

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks