I have an xml structure like this
<JJJ version="2.0" >
<Data >
<Object class="classX">
<k name="constname1">variable1</p>
<k name="constname2">variable2</p>
<k name="constname3">variable3</p>
</Object>
<Object class="classY">
<k name="constname1">variable11</p>
<k name="constname2">variable12</p>
<k name="constname3">variable13</p>
</Object>
I need to select ClassX node and in that value of atttribute containing constname1 (ie variable1
def parser = new XmlSlurper()
def mymo=records.'Data'.'Object';
def mytest = mymo.findAll{it.@class.text()=="ClassX"};
mytest.each{
it.'p'.each{
println it.@name.text() +'-'+ it.text() }
}
This is working. But instead of then comapring text in the loop I need to do something like this
def testme= mytest.'k'.find{ it.@name.text()=="constname1"}
This I am not getting right
However the below is right
println mymo.'k'.find{it.@name.text()=="constname1"}
But I want to restrict selection to the node for classX
Correcting your xml so it’s valid, gives:
is that what you wanted?