Given a nice, simple XML structure, XmlSlurper() can allow me to read values from it very easily.
def xml = "groovy"
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 = """
groovyjava xml"""
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
以上就是Can generic XML by parsed as nicely as simple XML in Groovy?的详细内容,更多请关注web前端其它相关文章!