嗨使用XmlParser的
麻烦,我想用“XML解析器”,以验证在soapUI中,我的XML响应。
我一直在玩弄这在Groovy脚本,如果我声明我可以访问标记,并指定我的XML Groovy的脚本中,像这样
如果我声明在脚本中的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()
}
任何帮助将不胜感激。
嗨。感谢您的回应。但我已经尝试过这一点,似乎没有任何工作,即parser.Body.'NS1:createShipmentResponse'。'NS1:integrationFooter'.warnings.warning.warningCode.each {... – chucknor