LibXML versus XML::Twig ?

S

surf

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.
 
I

Ian Stuart

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.
I can't tell you much about LibXML - however I *have* used XML::Twig.

XML::Twig is basically an extension to XML::parser - with lots of
additional functionality...

To give you an idea: I parse multi-megabyte XML files; breaking it down
into sub-components and transforming the XML segments into HTML.

www.xmltwig.com will help.
 
N

nic

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.

I use XML::parser, on which XML::Twig is based, and it does seem like a
nice module. I have also heard that LibXML is faster - but unfortunately
as you have found out, documentation is not that good. Maybe you should
look at the documentation for XML::LibXML
(http://search.cpan.org/~phish/XML-LibXML-1.58/). I am reading through it
now, and I am considering giving it a try.

Cheers

Nic
 
M

Michel Rodriguez

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::parser/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.
 
S

surf

Wow, the author of XML::twig responds to my post ... !

I have been reading your documentation and doing some XML::Twig
parsing.
I find it very usefull.

About a year ago or more someone at work first asked me about looking
into xml parsing and I got a book on
XSLT. Sort of like writting code in XML, not that great, although it
was all new to me and I was excited
after I got it to do the most simple things. We have an XML parser Java
used at work for certain specific XML files, but it's pretty complex
for what it does. Then I found XML::parser and played with that a
little and decided that was the best. Recently I was trading email war
stories from a perl monger I met from the web, he mentioned he did alot
of cool stuff with XML::Twig. We have a new product we use that exports
XML and I have decided to start playing with that using Twig and I
really like what I can do. I've been getting more into perl the last
couple years, most of my background is in C++, but I have been buying
all kinds of perl books and going on CPAN.
 
M

Michel Rodriguez

surf said:
Wow, the author of XML::twig responds to my post ... !

Hey, I wouldn't pass on an opportunity to tell the World about
XML::Twig ;--)

Seriously, this is a question that comes back quite often, in
one form or an other. So thaks for asking, and I took the opportunity
to include my answer to the docs of the module, and to the FAQ.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top