nagesh has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I have example XML file below. Some elements in XML have location. I want to sort the XML elements according to the "location" child element of each elements. In the same time I don't want to loose the XML tree structure i.e the parents and children after sort have to remain the same. I want to use the "X" attributes of the location for sorting. If "X" attributes are same then "Y" attribute gets the priority. The sort have to be ascending order. I was thinking of using the XML::DOM module for this, but I am confused as to how I should rebuild the XML according to the sort. I appreciate suggestions about to how to go about and any modules that could be of help to me.
thanks,
Nagesh
<?xml version="1.0" encoding="UTF-8"?> <VB.Form name="RFI002"> <VB.Frame name="framain"> <Font> <Name>Tahoma</Name> <Size>8.25</Size> <Charset>0</Charset> <Weight>400</Weight> <Underline>0 'False</Underline> <Italic>0 'False</Italic> <Strikethrough>0 'False</Strikethrough> </Font> <location X="0" Y="-120" /> <size H="4635" W="10455" /> <VB.Frame name="Frasch"> <BorderStyle>0 'None</BorderStyle> <location X="1920" Y="1800" /> <size H="495" W="2175" /> <formfield name="optschyes"> <type object="VB.OptionButton" /> <Font> <Name>Tahoma</Name> <Size>8.25</Size> <Charset>0</Charset> <Weight>400</Weight> <Underline>0 'False</Underline> <Italic>0 'False</Italic> <Strikethrough>0 'False</Strikethrough> </Font> <location X="0" Y="120" /> <size H="255" W="855" /> </formfield> <formfield name="optschno"> <type object="VB.OptionButton" /> <Font> <Name>Tahoma</Name> <Size>8.25</Size> <Charset>0</Charset> <Weight>400</Weight> <Underline>0 'False</Underline> <Italic>0 'False</Italic> <Strikethrough>0 'False</Strikethrough> </Font> <location X="840" Y="120" /> <size H="255" W="1095" /> </formfield> </VB.Frame> <VB.Frame name="Fracost"> <BorderStyle>0 'None</BorderStyle> <location X="1920" Y="2280" /> <size H="495" W="1935" /> <formfield name="optno"> <type object="VB.OptionButton" /> <Font> <Name>Tahoma</Name> <Size>8.25</Size> <Charset>0</Charset> <Weight>400</Weight> <Underline>0 'False</Underline> <Italic>0 'False</Italic> <Strikethrough>0 'False</Strikethrough> </Font> <location X="840" Y="120" /> <size H="255" W="1095" /> </formfield> <formfield name="optyes"> <type object="VB.OptionButton" /> <Font> <Name>Tahoma</Name> <Size>8.25</Size> <Charset>0</Charset> <Weight>400</Weight> <Underline>0 'False</Underline> <Italic>0 'False</Italic> <Strikethrough>0 'False</Strikethrough> </Font> <location X="0" Y="120" /> <size H="255" W="855" /> </formfield> </VB.Frame> <formfield name="Cmbreason"> <type object="VB.ComboBox" /> <location X="1920" Y="840" /> <size H="315" W="2175" /> </formfield> <formfield name="txtbehalf"> <type object="VB.TextBox" /> <Font> <Name>Tahoma</Name> <Size>8.25</Size> <Charset>0</Charset> <Weight>400</Weight> <Underline>0 'False</Underline> <Italic>0 'False</Italic> <Strikethrough>0 'False</Strikethrough> </Font> <Text>[Mr. Jim Mcdongaller (Org/Org Unit)]</Text> <location X="1920" Y="360" /> <size H="285" W="3985" /> </formfield> </VB.Frame> </VB.Form>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting XML elements
by IOrdy (Friar) on Feb 20, 2002 at 01:42 UTC | |
|
Re: Sorting XML elements
by gellyfish (Monsignor) on Feb 20, 2002 at 12:38 UTC |