Search code examples
javaxmlxmlbeans

order of parsed elements is lost in XMLBeans


I have a XML structure somewhat like this:

<root>
    <a/>
    <b/>
    <b/>
    <a/>
    <a/>
</root>

My XSD looks like this:

<xs:element name="root">
    <xs:complexType>
        <xs:sequence>
            <xs:choice maxOccurs="unbounded">
                <xs:element ref="a"/>
                <xs:element ref="b"/>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>
</xs:element>

<xs:element name="a" type="xs:string" />
<xs:element name="b" type="xs:string" />

I.e. i have a random sequence of two different sub tags.

Using XMLBeans i get a Root object with access methods: getAArray(), getBArray()

And here's my problem:
The tags are grouped by name and the original order (a,b,b,a,a) is lost.
But i need to know the order of those elements.

What is the best / easiest way to do that with XMLBeans?


Solution

  • Try

    xml.selectPath("./*")