Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: XML parsing vs Regular expressions

by ajt (Prior)
on Feb 16, 2008 at 21:59 UTC ( [id://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...


--
ajt

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 23:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found