I am new to this groovy. I am looking for all the videoGame nodes whose tag id attribute matches to "4".
def text = '''
<videoGames>
<videoGame category="A">
<id>3</id>
<name>testName 3</name>
<releaseDate>2001-03-10T00:00:00Z</releaseDate>
<tags attr="true">
<tag id="4">41</tag>
<tag id="3">31</tag>
</tags>
</videoGame>
<videoGame category="B">
<id>3</id>
<name>testName 3</name>
<releaseDate>2001-03-10T00:00:00Z</releaseDate>
<tags attr="true">
<tag id="3">41</tag>
<tag id="7">31</tag>
</tags>
</videoGame>
</videoGames>
'''
def videoGames = new XmlSlurper().parseText(text)
def games = videoGames.videoGame.'**'.find {
node -> node.name() == 'tag' && node.@id == '4'
}
println games
I am able to print the child node but I have not been successful to get the parent node. Any pointers?
The following code:
will produce the following output when run:
(newline after xml declaration in the output added by me).