An example of the xml:
<response version-api="2.0">
<value>
<books>
<book available="20" id="1" tags="">
<title>Don Xijote</title>
<author id="1" tags="Joel">Manuel De Cervantes</author>
</book>
<book available="14" id="2" tags"Jane">
<title>Catcher in the Rye</title>
<author id="2" tags="">JD Salinger</author>
</book>
<book available="13" id="3" tags="">
<title>Alice in Wonderland</title>
<author id="3">Lewis Carroll</author>
</book>
<book available="5" id="4" tags="Harry">
<title>Don Xijote</title>
<author id="4">Manuel De Cervantes</author>
</book>
</books>
</value>
</response>
Basically I am trying to append a string value of my choosing to all attributes called "tags". This is whether the "tags" attribute has a value or not and also the attributes are at different levels of the xml structure. I have tried the method appendNode() but that spits back a groovy runtime expression error. I have also looked at this stackoverflow question but I am not getting any closer to the answer I need. This is the code:
def rootFolder = new File('.').getCanonicalPath()
def response = new XmlSlurper().parse(new File(rootFolder + File.separator + 'src' + File.separator + 'metadata.xml'))
def tags = response.'**'.findAll { it['@tags']!='' }
tags.each{ t ->
def tagAttr = (t.@tags.value.toString())
println(tagAttr)
}
Anyone have any idea on how I can achieve this?