Die Groovy documentation in der Verarbeitung XML-Abschnitt erwähnt, dass breadthFirst()
ist auch auf die kürzere Syntax von *
. Allerdings endet die *
Nutzung eine Ebene unter dem übergeordneten Knoten nur bis durchlaufen:Groovy - XML Baum Traversal BreiteFirst() Methode mit * als syntaktischen Zucker
def books = '''\
<response>
<books>
<book available="20" id="1">
<title>foo</title>
<author id="1">foo author</author>
</book>
<book available="14" id="2">
<title>bar</title>
<author id="2">bar author</author>
</book>
</books>
</response>'''
def response = new XmlSlurper().parseText(books)
def bk = response.'*'.find { node ->
node.name() == 'book' && node['@id'].toInteger() == 2
}
assert bk.empty
während breadthFirst()
explizit mit tut, was erwarte ich, beides zu tun, welche Breiten ersten Traversal zu tun ist:
def books = '''\
<response>
<books>
<book available="20" id="1">
<title>foo</title>
<author id="1">foo author</author>
</book>
<book available="14" id="2">
<title>bar</title>
<author id="2">bar author</author>
</book>
</books>
</response>'''
def response = new XmlSlurper().parseText(books)
def bk = response.breadthFirst().find { node ->
node.name() == 'book' && node['@id'].toInteger() == 2
}
assert bk.title == 'bar' // bk is no longer an empty list of children
*
Semantik ist deutlich anders als breadthFirst()
. Ist das erwartetes Verhalten oder habe ich etwas im doc verloren?