Given a nice, simple XML structure, XmlSlurper() can allow me to read values from it very easily.
def xml = "<html><head><title>groovy</title></head></html>"
def html = new XmlSlurper().parseText(xml)
println html.head.title
Is there a way to make this simple tree navigation possible for generic (type-based, etc) XML. Ideally, in the snippet of code below, I'd like to walk the values by their name attribute, but instead, I have to do all this searching:
def genxml = """
<doc>
<lst name = "head">
<str name = "title">groovy</str>
<str name = "keywords">java xml</str>
</lst>
</doc>"""
def doc = new XmlSlurper().parseText(genxml)
println doc.lst.find { it.@name == "head" }.str.find { it.@name == "title" }
Is there a way to walk this just as:
println doc.head.title