in reply to Re: regex and XML
in thread regex and XML

Another bit of the puzzle is that in the example you have give, the regular expression is being quoted using pipe symbols (|) instead of the usual forward slash.

Whoever wrote the regex probably did this to avoid having to escape the / in the closing tag. Personally, I always use /, so I would have written $xml =~ /<$fieldname>(.*?)<\/$fieldname>/i

Talking about parsing XML, what easy-to-use XML parser would the monks recommend? From the quick look I have taken at the documentation of a couple of XML parsers, it would take a week for me to figure out how to do something like "print out the content of every XYZ tag in the document, each one on a new line".

Replies are listed 'Best First'.
Re^3: regex and XML
by CountZero (Bishop) on Dec 13, 2010 at 17:45 UTC
    If you just want to extract certain elements, I'd say XPath is the way to go. There is XML::XPath and XML::XPath::Simple.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James