[xsd-users] Preserving XML element order

Boris Kolpackov boris at codesynthesis.com
Mon Feb 15 11:02:37 EST 2010


Barrie,

Barrie Kovish <barrie.kovish at singularsoftware.com> writes:

> I know that in one case we need to insert complex elements to a series 
> of similar elements.  Likely in the future we would need to do the same 
> plus perform some sort of fix up of other elements which were dependent 
> upon the element order.  For example
> 
> Starting XML:
> <A>x</A>  <!-- implicit index 1-->
> <A>y</A>  <!-- implicit index 2-->
> <A>z</A>  <!-- implicit index 3-->
> 
> Changed XML:
> <A>x</A>  <!-- implicit index 1-->
> <A>y</A>  <!-- implicit index 2-->
> <A>u</A>  <!-- implicit index 3-->
> <A>z</A>  <!-- implicit index 4-->
> 
> Other elements in the file will contain the 1, 2, and 3.  We will need to 
> fix them up to have the new and correct indices.  The contents x,y,z, u 
> can also be complex or simple elements.

I see several ways how this can be done fairly easily with the 
substitution group approach[1]. For example, you could customize 
the object model to maintain a map of "first complex element" 
(i.e., the element with actual content) to all the "referencing
elements" (i.e., the elements with just the id). This map would 
be stored in the root of the object model. The complex elements 
would then automatically add themselves to this map. Once you 
need to adjust the id of some element and all its references, 
you can use this map to quickly find all the places that need
changing. 

[1] http://www.codesynthesis.com/pipermail/xsd-users/2008-May/001697.html

Boris



More information about the xsd-users mailing list