在SoapUI Pro中使用XmlParser时出现问题
嗨,我正在尝试使用'xml解析器'来验证我在SoapUI Pro中的xml响应。
我一直在用一个时髦的脚本来玩这个,如果我在groovy脚本中声明并分配我的xml就可以访问标签
如果我在脚本中声明xml,这是有效的。
def xml = """
<NS1:createShipmentResponse xmlns:NS1="http://www.royalmailgroup.com/api/ship/V1">
<NS1:integrationHeader>
<dateTime xmlns="http://www.royalmailgroup.com/integration /core/V1">2013-12-24T22:20:34</dateTime>
<version xmlns="http://www.royalmailgroup.com/integration/core/V1">1</version>
<identification xmlns="http://www.royalmailgroup.com/integration/core/V1">
<applicationId>111111113</applicationId>
<transactionId>420642961</transactionId>
</identification>
</NS1:integrationHeader>
<NS1:completedShipmentInfo>
//xml not complete, other info in here.
</NS1:completedShipmentInfo>
<NS1:integrationFooter>
<warnings xmlns="http://www.royalmailgroup.com/integration/core/V1">
<warning>
<warningCode>W0022</warningCode>
<warningDescription>The customerReference specified is longer than 12 characters and has been truncated</warningDescription>
</warning>
<warning>
<warningCode>W0026</warningCode>
<warningDescription>The departmentReference specified is invalid and will be ignored</warningDescription>
</warning>
</warnings>
</NS1:integrationFooter>
</NS1:createShipmentResponse>
"""
def parser = new XmlParser().parseText(xml)
parser.'NS1:integrationFooter'.warnings.warning.warningCode.each{
log.info it.text()
}
但是,当我从Soap响应中实例化xmlParser变量时,它似乎在正在运行的测试实例中不起作用。
def response = context.expand( '${createShipment_v04#Response}' );
我知道解析器变量已经分配了xml响应,因为我可以将它打印到日志中。
即。 log.info解析器打印...
Wed Jan 08 16:33:38 GMT 2014:INFO:{http://schemas.xmlsoap.org/soap/envelope /}Envelope[attributes={}; value=[{http://schemas.xmlsoap.org/soap/envelope/}Body[attributes={}; value=[{http://www.royalmailgroup.com/api/ship/V1}createShipmentResponse[attributes={}; value=[{http://www.royalmailgroup.com/api/ship/V1}integrationHeader[attributes={}; .......
但是当我从soap响应中实例化xmlParser请求时,代码下面没有打印任何内容。
parser.'NS1:integrationFooter'.warnings.warning.warningCode.each{
log.info it.text()
}
非常感谢任何帮助。
答案 0 :(得分:0)
我相信你的工作水平不对。
... parser.Body
答案 1 :(得分:0)
确定。事实证明我不需要'NS1:'部分。以下作品..
slurper.Body.createShipmentResponse.integrationFooter.warnings.warning.warningCode.each{
log.info it.text()
}
答案 2 :(得分:0)
以下应该工作:
def response = context.expand( '${createShipment_v04#Response}' );
def parser = new XmlSlurper().parseText(response)
def warningCodes = parser.'**'.findAll {
it.name()=='warningCode'
}
warningCodes.each {
log.info it
}