节点我有如下的XML响应:如何遍历XML孩子使用Groovy脚本
<ns:Envelope xmlns:tns="http://schemas.xmlsoap.org/soap/envelope/">
<ns:Body>
<ns:response xmlns:svc="http://...serviceNameSpace"
xmlns:ent="http://....entitiesNameSpace">
<ns:customer>
<ns:contact>
<ns:type>firstclass</ns:type>
<ns:email>[email protected]</ns:email>
<ns:details>
<ns:name>Kevin</ns:name>
<ns:area>Networking</ns:area>
</ns:details>
<ns:address>
<ns:code>39343</ns:code>
<ns:country>US</ns:country>
</ns:address>
</ns:contact>
<ns:contact>
<ns:type>secondclass</ns:type>
<ns:email>[email protected]</ns:email>
<ns:details>
<ns:name>John</ns:name>
<ns:area>Development</ns:area>
<ns:address>
<ns:code>23445</ns:code>
<ns:country>US</ns:country>
</ns:contact>
</ns:customer>
</ns:response >
</ns:Body>
我想这个迭代的childNodes细节和地址验证与请求属性响应。但我可以断言电子邮件,但无法详细(姓名和地区)和地址(代码和国家)。下面是我使用
import groovy.xml.*
def envelope = new XmlSlurper().parseText(messageExchange.responseContentAsXml)
def type = 'secondclass'
def emailAddress= ${properties#emailAddress}
envelope.'**'
.findAll { it.name() == 'contact' }
.findAll { it.type.text().contains(type) }
.each {
assert emailAddress== it.emailAddress.text()
}
请帮我在遍历节点的详细信息(姓名和区域及地址码和国家)的断言
你的意思是,如果你收到的响应,相同的数据在被送往说请求?然后,请添加您的请求以及编辑帖子。 – Rao
Nope请求与响应数据不同。这是不同的,我设置属性与价值观分开。我想通过验证具有已设置属性的xml数据来断言它。 – Kumar