http://www.perlmonks.org?node_id=510097

rtremaine has asked for the wisdom of the Perl Monks concerning the following question:

I need to process some XML docs. Seems to be a staggering array of modules to choose from. Ideally, I think I would like to be able to just feed it a schema (xsd) and the xml doc and be able to reference any element via a hash or object. Doc's are small, less than 100 total elements. Suggestions? Thanks again!

Replies are listed 'Best First'.
Re: XML Processing
by Tanktalus (Canon) on Nov 19, 2005 at 16:02 UTC

    Personally, I use XML::Twig for all things XML. It may be overkill for small things, but when you have a swiss army knife as your tool, well, all things look like something to cut, slice, uncork, hammer, screw, magnify, eat with a spoon, a fork, ... ;-)

    However, it does sound like XML::Simple may be a simpler choice for you - you probably want to Super Search for XML::Simple to see the types of problems that XML::Simple doesn't solve so you can evaluate for yourself prior to actually using it. Off the top of my head, if your doc has both attributes and content for the same element, saving your doc back out may lose the distinction. There may be ways around that, but a Super Search would likely prove helpful to do it right up front.

Re: XML Processing
by davido (Cardinal) on Nov 19, 2005 at 16:32 UTC

    I used to be sold on XML::Simple for most XML needs, but as planetscape pointed out to me not too long ago, XML::Twig will handle some XML data that XML::Simple simply chokes on.

    As I dug a little deeper into XML::Twig I found that it still has a simple mode that one can use, similar to XML::Simple's XMLin() method. In fact, it tries to closely emulate the behavior of XML::Simple when operating in simple mode. But in addition to the simple things, it can do so much more too.

    So I've begun re-implementing some of my existing tools using XML::Twig instead, and it gets my recommendation.


    Dave