GitHub user manouti opened a pull request:
https://github.com/apache/groovy/pull/517
Differentiate between XML breadthFirst() traversal and * navigation
The analogy between '*' and breadthFirst() traversal seems wrong. The
former only traverses one level, while the latter searches through the next
levels as well. See
http://stackoverflow.com/questions/42985716/groovy-xml-tree-traversal-breadthfirst-method-using-as-syntactic-sugar:
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
> whereas using breadthFirst() explicitly does what I expect both to do
which is to do breadth-first traversal:
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
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/manouti/groovy patch-1
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/groovy/pull/517.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #517
----
commit e44d36531c46db13bdfe398de7ec852be4b02aa0
Author: manouti <[email protected]>
Date: 2017-03-23T21:45:20Z
Differentiate between XML breadthFirst() traversal and * navigation
The analogy between '*' and breadthFirst() traversal seems wrong. The
former only traverses one level, while the latter searches through the next
levels as well. See
http://stackoverflow.com/questions/42985716/groovy-xml-tree-traversal-breadthfirst-method-using-as-syntactic-sugar.
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---