[xsd-users] Preserving XML element order
Boris Kolpackov
boris at codesynthesis.com
Thu Feb 11 07:12:31 EST 2010
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