Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: XML parsing vs Regular expressions

by ajt (Prior)
on Feb 16, 2008 at 21:59 UTC ( #668357=note: print w/ replies, xml ) Need Help??

in reply to XML parsing vs Regular expressions

Many an insane person started out sane, before they tried to use regular expressions on XML. While it starts easy, it very quickly descends into chaos. As a general rule if you are working with XML, use a module that uses a real XML parser of some kind, XML::LibXML can be complicated to learn but it is very fast and complete. XML::Twig is another fast tool, and it even includes a regular expression on XML tool...


Comment on Re: XML parsing vs Regular expressions
Replies are listed 'Best First'.
Re^2: XML parsing vs Regular expressions
by Joost (Canon) on Feb 16, 2008 at 23:57 UTC
    ajt's right. You really do want to use XML tools for processing XML. The only time you may possibly do better with regexes is when you're writing a one-off script that only parses a very regular short file that you've inspected before running the script, and it generally takes a couple of tries even to get that right.

    In other circumstances just the fact that a real XML parser will throw a huge tantrum on invalid input will already safe you a lot of work. And that's without mentioning some of the really nice interfaces that modules like XML::Twig can provide.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://668357]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2015-10-08 21:27 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (228 votes), past polls