The XmlSlurper sample from the documentation
fails these additional asserts:
On on an XML, where some 'cars' don't have a 'country' child this expression will still return all countries: records.cars.country.parent(). It should only return 'cars' with at least one 'country' child.
Fixing the problem involved:
- Adding a public parent() method and parent private property to Node
- Implementing an additional subclass NodeParents of GPathResult
- Simplifying childNodes() in NodeChildren, so that it utilizes the classes nodeIterator()
- Implementing ParentNodes with a nodeIterator() override
- Cleaning up FilteredNode children to follow the same pattern
- Instantiating ParentNodes in GPathResult.parent()
- Calling parent() for property '..'
And as an added refinement to the GPath syntax:
- Defining GPathResult.getAt(closure) to call findAll(closure)
All changed source code in groovy.util.slurpersupport is in the attached zip. The groovy source contains the asserts. All of which pass.
This fix supersedes the proposed fix for #6122