Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

best xml parser to use

by ftumsh (Scribe)
on Jul 06, 2006 at 18:03 UTC ( [id://559636]=perlquestion: print w/replies, xml ) Need Help??

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

Lo all,
Given that
1) the xml I have to use is quite simple (no cdata or PI etc)
2) but possibly large (< 5meg)
3) I need to know a tag before it's children are parsed
4) have a small memory footprint
5) be very fast
6) Linux only

Should I be using XML::Parser or XML::LibXML?

Thx
John

Replies are listed 'Best First'.
Re: best xml parser to use
by Tanktalus (Canon) on Jul 06, 2006 at 18:07 UTC

    My general decision tree goes sorta like this (non-XML parts removed):

    /----------\ +-----------+ < Parse XML? > --NO>-- | (removed) | \----------/ +-----------+ | YES V | +---------------+ | Use XML::Twig | +---------------+
    Hopefully this decision tree helps you decide what is best.

    ;-)

      heh :)
      I normally always use xml::twig, but I don't actually know the format of xml so I can't in this case. I've been googling and I'm going to try xml::sax.

      I appear to have only got xml::libxml::sax, is this good enough? the pod mention it might not be any good for production use. What others could I use?

        What do you mean by "I don't actually know the format of xml"? How will switching parsers (though, technically, XML::Twig is a front-end, not a parser itself) fix that?
      if ($xml->is_simple() and $xml->is_table_like()) { use XML::RAX; } elsif (size($xml) < too_big()) { use XML::Simple; } else { use XML::Twig; ... my $Data = $DataObj->simplify(forcearray => [...], keyattr =>{ ... } +, group_tags => {...}); }

      Update 2007-2-6: Tastes change. While I would probably still use XML::RAX for some tasks with table-like XML and XML::Simple for very simple XMLs, I'd most probably use my XML::Rules now. May look a bit twisted at first, but it's convenient and powerfull. IMHO of course ;-)

Re: best xml parser to use
by planetscape (Chancellor) on Jul 06, 2006 at 19:28 UTC

      Agreed, although I sometimes still use XML::TreeBuilder.

      Love Tanktalus's decision tree though. :)


      DWIM is Perl's answer to Gödel
Re: best xml parser to use
by xdg (Monsignor) on Jul 10, 2006 at 12:54 UTC

    I'm not sure how it stacks up against these criteria, but if you're not 100% sure that your incoming data is entirely valid, you might want to check out XML::Liberal (a standin for LibXML). Avoiding re-parsing a large XML file because of a small nit might be worthwhile form of efficiency.

    The author gave a nice Lightning Talk about it at YAPC::NA.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://559636]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-19 21:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found