Perl XML modules

XML::Simple

Provides an extremely simple API to read and write XML into and out of Perl native data structures. Simple for simple things, but has some gotchas, which led to the creation of a "strict mode" for the API and a guide for switching to XML::LibXML.

XML::Twig

Very powerful module to read and process even huge XML documents. Allows you to process the XML one "twig" (tag with all its children and content) at a time, giving you the data either as native Perl datastructure or a structure of objects. See also: xmltwig.com

XML::Rules

An event based XML parser. It allows you to specify actions to execute once a tag is fully parsed (including the children) and passes the data produced by the actions to the ones attached to the parent tags.

XML::LibXML

This is really the best option in the general case; very powerful. It’s a wrapper for the libxml2 C library so it’s very fast and has low memory usage. It has a complete and compliant implementation of XPath, which is almost the only sane way to deal with XML. It takes a little to get used to the module because there is only terse reference documentation, but it’s worth toughing out the initial learning curve, and if you already know the DOM API you have a sizeable head-start. There is also XML::LibXSLT which uses the c library libxslt (a companion to libxml2) to perform XSL Transformations (XSLT).

See also: The Perl XML FAQ


Modules that should not be used any more

These modules have had their use but are no longer properly maintained, and there are better alternatives to using them:

  • XML::Parser was the first XMLmodule for Perl. It is based on the expat library. It is very low level, and barely maintained. In most cases XML::LibXML will be faster and more powerful, and XML::Twig more convenient. XML::Parser is still a useful module, but more as a low-level layer on which more convenient modules can be built.
  • XML::XPath appears to be no longer maintained, XML::LibXML is more efficient, more powerful and better maintained. It is also really easy to port code from XML::XPath to XML::LibXML as they both implement the DOM and XPath in similar ways.
  • XML::DOM was the first implementation of the DOM in Perl. It is based on XML::Parser and expat. It is now barely maintained, and XML::LibXML should be used instead. Porting the code should be straightforward. If you can't switch to XML::LibXML, because you can't or don't want to install libxml2, then at least have a look at XML::DOM::XPath which adds XPath support to XML::DOM.

ref link: https://www.socialtext.net/perl5/index.cgi?recommended_xml_modules

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s