Ordering of Elements in XML using Perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skrishnaveni
    New Member
    • Jan 2007
    • 4

    Ordering of Elements in XML using Perl

    Hi,

    I have an XML with lots of unordered tags. Some of the attributes in XML require to be renamed. I have tried using XML::XSLT. Although I am able to generate the desired output, it takes a lot of time. Another problem is that the program gets stuck if XML is huge. Is any other way to generate the desired XML in Perl.

    Thanks in advance......
  • rickumali
    New Member
    • Dec 2006
    • 19

    #2
    Originally posted by skrishnaveni
    I have an XML with lots of unordered tags. Some of the attributes in XML require to be renamed. I have tried using XML::XSLT. Although I am able to generate the desired output, it takes a lot of time. Another problem is that the program gets stuck if XML is huge. Is any other way to generate the desired XML in Perl.
    When you say "some of the attributes in XML require to be renamed", do you mean that you want to go from this:

    <ELEMENT ATTRIB="Foo">Da ta</ELEMENT>

    to this:

    <ELEMENT RENAMED="Foo">D ata</ELEMENT>

    If the above is the kind of transformation you want, you could just use the classic Perl search and replace one-liner:

    perl -p -i -e 's/ATTRIB/RENAMED/g' *.html

    I don't often use XSLT for things like this. Yes, you will need to XSLT someday, but if all you're doing is renaming tags, you might be able to get away with using plain old Perl.

    Comment

    • skrishnaveni
      New Member
      • Jan 2007
      • 4

      #3
      Hi,

      Thanks for the reply. Renaming the attributes is only one of small issues. The tags should also come in an ordered manner.

      One way of achieving this is to create an array with tag names. Parsing through the array we can arrange the tags in an XML file. But this takes hours together especially if the file is huge.

      XSLT seemed to be answer to me. Here we can define the order of tags, case-sensitivity of elements etc and many more features. I am trying to use many more features in it. Although the time compared to the above program was remarkable, but still time taken seemed to be too much for large files. The line in the code $xslt->serve($xmlfile ) seems to take a lot of time as the whole file is read into a line.

      Comment

      Working...