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>

In reply to Sorting XML elements by nagesh

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.