我有以下SOAP响应:
我需要选择地址并且nId具有nIdType =“ACTIVE”。
可能会有更多的地址和nId,我需要选择第一场比赛。
我写了groovy脚本并没有取得任何成功。请帮助我,因为我是新的
可能所有地址都可能有或没有nId
我有test属性,我需要更新Address和nId
我需要通过groovy脚本实现
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:GetD xmlns:ns2="http://xyxz/pqr" xmlns:ns3="http://pqp/ptr" xmlns:ns4="http://nhgg./ns">
<ns2:du>
<ns2:Address>UUUUUU</ns2:macAddress>
</ns2:du>
<ns2:du>
<ns2:Address>XXXXXXX</ns2:macAddress>
</ns2:du>
<ns2:du>
<ns2:Address>PQWWEEE</ns2:macAddress>
<ns2:dP>
<ns2:pN>1</ns2:pN>
<ns2:sE>
<ns2:nId>08767727</ns2:nId>
<ns2:nIdType>ACTIVE</ns2:nIdType>
<ns2:sE>
</ns2:dP>
</ns2:du>
<ns2:du>
<ns2:Address>TTTTTTTT</ns2:macAddress>
</ns2:du>
</ns2:GetD>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
答案 0 :(得分:2)
您可以执行此操作(我必须向您的XML添加结束</SOAP-ENV:Envelope>
标记,并将</ns2:macAddress>
更改为</ns2:Address>
以使其成为有效的XML格式
def xml = '''<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
| <SOAP-ENV:Header/>
| <SOAP-ENV:Body>
| <ns2:GetD xmlns:ns2="http://xyxz/pqr" xmlns:ns3="http://pqp/ptr" xmlns:ns4="http://nhgg./ns">
| <ns2:du>
| <ns2:Address>UUUUUU</ns2:Address>
| </ns2:du>
| <ns2:du>
| <ns2:Address>XXXXXXX</ns2:Address>
| </ns2:du>
| <ns2:du>
| <ns2:Address>PQWWEEE</ns2:Address>
| <ns2:dP>
| <ns2:pN>1</ns2:pN>
| <ns2:sE>
| <ns2:nId>08767727</ns2:nId>
| <ns2:nIdType>ACTIVE</ns2:nIdType>
| </ns2:sE>
| </ns2:dP>
| </ns2:du>
| <ns2:du>
| <ns2:Address>TTTTTTTT</ns2:Address>
| </ns2:du>
| </ns2:GetD>
| </SOAP-ENV:Body>
|</SOAP-ENV:Envelope>'''.stripMargin()
def a = new XmlSlurper().parseText( xml ).Body?.GetD?.du?.find { node ->
node.dP?.sE?.nIdType.text() == 'ACTIVE'
}
println "First Active Address = ${a?.Address?.text()}"
打印:
First Active Address = PQWWEEE
但很难从你的问题中确切地说出你在追求什么