in reply to The mostly used xml parser

If XML::Simple does the job for you, use it. It is widely used and for simple applications won't go out of fashion in a hurry.

If you need more power then take a look at XML::twig, especially if you are filtering XML, or perhaps XML::TreeBuilder if you want to move elements around.


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^2: The mostly used xml parser
by Tanktalus (Canon) on Oct 05, 2005 at 14:26 UTC

    I've not found anything XML::Twig couldn't do. Including moving elements around. ;-) In fact, I use XML::Twig to manipulate HTML tables to "automatically" re-insert the header of the table every x rows (so you don't need to scroll too far to see the header info), and to change the class for each row (tr element) to alternate so that CSS can come by and change the background colour to make it again easier to follow with the eye.

    Perhaps XML::TreeBuilder would be easier for this. I'm not sure. Maybe XML::Twig is just my metaphorical hammer, and all XML problems seem to be nails to me. Or perhaps XML::Twig is the swiss-army-knife of XML processors, and I chose well. Up to you to decide. ;-)

      A month ago I'd not have mentioned XML::Twig - XML/HTML::TreeBuilder was my hammer. Having seen mention of XML::Twig] so frequently I've started using it too and it does do filtering (my first application for it) very nicely!

      What I'd like would be an HTML::Twig. Might not be as "easy" to write though :).


      Perl is Huffman encoded by design.

        Processing HTML is not too difficult, as long as tidy is around:

        perl -MXML::Twig -e'open( my $fh, "tidy -asxml -quiet pm.html 2>/dev/null| ") or die $!; XML::Twig->parse( $fh)'

        Keeping the output similar to the input is of course much harder, as in this case XML::Twig does not see the original file.

        Here I pay for the fact that XML::Twig does not accept a SAX stream as input, or I could use XML::LibXML::SAX and get HTML parsing for free (SAX was quite new when I started writing XML::Twig, and now it is coupled very strongly with XML::Parser).