Problem with order of elements in sequence

Help
Indrek
2013-07-07
2013-07-07
  • Indrek
    Indrek
    2013-07-07

    Hi!

    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:complexType>
        <xsd:sequence>
          <xsd:choice minOccurs="0" maxOccurs="unbounded">
            <xsd:element ref="TA"/>
            <xsd:element ref="TB"/>
            <xsd:element ref="TC"/>
          </xsd:choice>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:element>
    

    According to this definition we can have following XML data:

    <M>
      <TC>C</TC>
      <TA>A2</TA>
      <TB>B1</TB>
      <TA>A1</TA>
    </M>
    

    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