xml - 解析Soap响应-XML/XPATH(在soapUI中)(SoapUI响应中的命名空间)

标签 xml soap xpath soapui

如果我有如下所示的Soap回复

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns0:SomeResponse xmlns:ns0="urn:ABC:EFG:HIJ:Some_WS">
         <ns0:ID>6384</ns0: ID>
         <ns0:Some_ID>10530</ns0: Some_ID >
         <ns0:Status>SomeStatus</ns0:Status>
         <ns0:Number>INT1037;INT1027;</ns0: Number>
      </ns0:SomeResponse >
   </soapenv:Body>
</soapenv:Envelope>


如何获取Some_ID值。我在SoapUI中使用以下代码来检索Some_ID的值。

...
def response = tstep.getPropertyValue("response");
def gutils = new com.eviware.soapui.support.GroovyUtils( context );
def holder = gutils.getXmlHolder("$response");
// define namespace
holder.namespaces["ns0"] = "http://www.w3.org/2001/XMLSchema-instance"
def val1 = holder.getNodeValue("//ns0:SomeResponse/ns0:Some_ID");
log.info(val1)


但是log.info给了我null值。

最佳答案

要仅检索一个特定值,可以使用以下简单方法:

def val1 = context.expand('${TestStepName#Response#//*:Some_ID}')


对于更复杂的解析,您将不得不使用XmlHolderXmlParserXmlSlurper。您可以从official documentation了解这些内容。

在脚本中,尝试将tstep.getPropertyValue("Response")与大写R一起使用。

关于xml - 解析Soap响应-XML/XPATH(在soapUI中)(SoapUI响应中的命名空间),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30223774/

相关文章:

php - xml 错误 xsl 样式表

sql - 如何下载网页并用SQL解析

xml -/.. xpath在xsl模板中的作用

xml - XPath运算符:某些子元素包含子字符串

python - API测试: Postman vs Python Requests

php - 如何在 php 中接收 xml 请求并发送响应 xml?

Node.js SOAP : invalid message definition for rpc style binding

java - 在 Android 中实现 SOAP API

java - 使用 WSDL 生成客户端代码后如何摆脱 WSDL 依赖性?

selenium - 如何在Selenium Webdriver(Python)中使用变量名存储包含特定文本的元素来存储字符串?