Searching XML element in whole document with Groovy XmlParser

I'm using the Groovy XmlParser to read some XML document. This works fine as long as I know where the elements are located in the tree. However I haven't yet found a way to search the whole XML document for an element like e.g. in XPath //ElementName.

What's the Groovy way of doing this?


Looking for something like this?

def xml = 

def parsed = new XmlParser().parseText(xml)
assert ['John', 'Tony', 'Captain'] == 
          parsed.depthFirst().findAll { == 'firstName' }*.text()

also (as mentioned by Tim) you can use '**' for depthFirst search

assert ['John', 'Tony', 'Captain'] == 
          parsed.'**'.findAll { == 'firstName' }*.text()

Need Your Help

Handle special characters in mysql search e.g. Sigur Rós

php mysql regex database

My database features names with special characters e.g. Sigur Rós

jqPlot target that doesn't have a static id

javascript jquery charts jqplot

I'm just playing with jqplot for a few hours but I couldn't find how to specify the target in a more specific jquery way.