I have a simple XML string, that is more or less always the same. I’d rather avoid using an XML parser for such a little piece of code, and I though Regexp would help.
The XML string looks like :
<?xml version="1.0"?>
<methodCall>
<methodName>weblogUpdates.extendedPing</methodName>
<params>
<param>
<value>Official Google Blog</value>
</param>
<param>
<value>http://googleblog.blogspot.com/</value>
</param>
<param>
<value>http://googleblog.blogspot.com/</value>
</param>
<param>
<value>http://googleblog.blogspot.com/atom.xml</value>
</param>
</params>
</methodCall>
I want to extract the values of each param (and maintain the order).
I came up with /<value>(.*)<\/value>/xi but that just macthes the very first value :/
Parsing XML with Ruby is trivial, please don’t try to parse XML with a regular expression – it is notoriously difficult and error-prone.
While it may be tempting to try and use a regular expression, please don’t. No matter how hard you try to smash that nail with the screwdriver it won’t work as a hammer – please use one of the many wonderful hammers at your disposal.