Showing posts from October, 2011

Groovy XML Parser Gotcha - it's not a Map your parsing!

When I first looked at examples of using the Groovy XmlParser it appeared that the parser took some nice raw XML and turned it into a map for easy traversing. I could take the following source:


And parse it find the eye color like this:

def xml = new XmlParser().parseText(xmlSrc)
assert xml.person.face.eyes.text() == 'blue'

Confident in my understanding, I thought it would be trivial to handle the following XML source I was receiving from a domain registrar:

<?xml version="1.0"?>
<ErrCount> 1</ErrCount >
&ly;Err1> Do main name not available </Err1>

I parsed the source in order to extract the errors from the response as follows:

def xml = new XmlParser().parseText(xm…