[xsd-users] Preserving XML element order
Barrie Kovish
barrie.kovish at singularsoftware.com
Thu Feb 11 11:01:03 EST 2010
Boris,
There is probably another aspect of the schema I should mention. The various element types are shared. By this I mean the following:
<xs:element name='W'>
<xs:complexType>
<xs:choice minOccurs='0' maxOccurs='unbounded'>
<xs:element ref='A'/>
<xs:element ref='B'/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name='X'>
<xs:complexType>
<xs:choice minOccurs='0' maxOccurs='unbounded'>
<xs:element ref='A'/>
<xs:element ref='C'/>
</xs:choice>
</xs:complexType>
</xs:element>
So elements named A are shared between elements named X and W. This sort of thing is used a lot in this schema.
Barrie
On 2010-02-11, at 4:12 AM, Boris Kolpackov wrote:
> Hi Barrie,
>
> Barrie Kovish <barrie.kovish at singularsoftware.com> writes:
>
>> I am reading an XML file in and writing it out using classes generated
>> by XSD. In general I need to make a few simple modifications to the XML
>> file. But even if I don't modify the XML file the order of the elements
>> is not preserved. i.e. if the XSD classes read in
>> ...
>> <X>1</X>
>> <Y>2</Y>
>>
>> The XSD classes might write out
>> ...
>> <Y>2</Y>
>> <X>1</X>
>
> There are certain XML Schema use-cases where this can happen due to the
> flattening of the compositor structure in the C++/Tree mapping. For
> previous discussions of this issue see:
>
> http://www.codesynthesis.com/pipermail/xsd-users/2008-May/001697.html
> http://www.codesynthesis.com/pipermail/xsd-users/2008-June/001739.html
>
>
>> This is a big problem for me because the program which uses these XML
>> files is sensitive to the order of the elements. Note that the schema
>> does note impose an order on the elements and the program which
>> generates the XML files does not order the elements in a specific way.
>> However it is important for a specific document that the order not
>> change.
>
> Can you show the relevant schema fragments?
>
>
>> Is there a solution to this?
>
> There are several ways in which this can be worked around. But I will
> need to see the schema to be able to make a suggestion.
>
> There is also the C++/Hybrid[1] mapping in XSD/e[2] which recreates the
> compositor structure precisely and preserves the element order in all
> cases. While XSD/e was designed primarily for mobile/embedded systems,
> if configured to use STL, etc., it can also be used in general-purpose
> applications.
>
> [1] http://www.codesynthesis.com/products/xsde/c++/hybrid/
> [2] http://www.codesynthesis.com/products/xsde/
>
> Boris
More information about the xsd-users
mailing list