我有一个这样的xml结构
<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>
我需要选择 ClassX 节点并在包含 constname1 的属性值中(即 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() }
}
这是有效的。但是,我需要做这样的事情,而不是循环中的comapring文本
def testme= mytest.'k'.find{ it.@name.text()=="constname1"}
这我不正确
但是下面是正确的
println mymo.'k'.find{it.@name.text()=="constname1"}
但我想将选择限制为 classX 的节点