I have a legacy file format which I'm converting into XML for processing. The structure can be summarised as:
<A>
<A01>X</A01>
<A02>Y</A02>
<A03>Z</A03>
</A>
The numerical part of the tags can go from 01 to 99 and there may be gaps. As part of the processing certain records may have additional tags added. After the processing is completed I'm converting the file back to the legacy format by iterwalking the tree. The files are reasonably large (~150,000 nodes).
A problem with this is that some software which uses the legacy format assumes that the tags (or rather fields by the time it's converted) will be in alpha-numeric order but by default new tags will be added to the end of the branch which then causes them to come out of the iterator in the wrong order.
I can use xpath to find the preceeding sibling based on tag name each time I come to add a new tag but my question is whether there's a simpler way to sort the tree at once just prior to export?
Edit:
I think I've over summarised the structure.
A record can contain several levels as described above to give something like:
<X>
<X01>1</X01>
<X02>2</X02>
<X03>3</X03>
<A>
<A01>X</A01>
<A02>Y</A02>
<A03>Z</A03>
</A>
<B>
<B01>Z</B02>
<B02>X</B02>
<B03>C</B03>
</B>
</X>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…