surf said:
I heard that LibXML is the best, so someone says, but I have found
much better documentation with examples for XML::Twig and am
considering using that to get started
on some XML parsing just for that reason alone. I am wondering however
what people might have to say in reagrds to these two XML processing
components ...
I have the Perl XML book, it hardly has more than a few pages on
LibXML, none on Twig,
but I found a huge and very usefull doc on Twig on CPAN and other
places. The CPAN LibXML doc is very terse with no examples and the
xmlsoft doc seems to be for the C part and lacks many usefull examples.
A completely biased opinion (see my email address ;--):
XML::LibXML, actually libxml2, sticks to the standards, and implements a
good number of them in a rather strict way: XML, XPath, DOM, RelaxNG, I
must be forgetting a couple (XInclude?). It is fast and rather frugal
memory-wise.
XML::Twig is older: when I started writing it XML:
arser/expat was the
only game in town. It implements XML and that's about it (plus a subset
of XPath, and you can use XML::Twig::XPath if you have XML::XPath
installed for full support). It is slower and requires more memory for a
full tree than XML::LibXML. On the plus side (yes, there is a plus
side!) it lets you process a big document in chunks, and thus let you
tackle documents that couldn't be loaded in memory by XML::LibXML, and
it offers a lot (and I mean a LOT!) of higher-level methods, for
everything, from adding structure to "low-level" XML, to shortcuts for
XHTML conversions. It also DWIMs quite a bit, getting comments and
non-significant whitespaces out of the way but preserving them in the
output for example. As it does not stick to the DOM, is also usually
leads to shorter code than in XML::LibXML.
Beyond the pure features of the 2 modules, XML::LibXML seems to be
prefered by "XML-purists", while XML::Twig seems to be more used by Perl
Hackers who have to deal with XML. As you have noted, XML::Twig also
comes with quite a lot of docs, but I am sure if you ask for help about
XML::LibXML here or on Perlmonks you will get answers.
Note that it is actually quite hard for me to compare the 2 modules: on
one hand I know XML::Twig inside-out and I can get it to do pretty much
anything I need to (or I improve it ;--), while I have a very basic
knowledge of XML::LibXML. On the other hand, I am painfully aware of
some of the deficiencies and potential bugs that lurk in XML::Twig, even
though you are unlikely to be affected by them (unless for example you
need to process the DTD), while I haven't looked into XML::LibXML so it
still looks shinny and clean to me.