2016-05-06 49 views
0

获得在XPath节点值我不是不能够在得到了“的ID号”节点值低于响应XML不能通过getNodeValue功能在常规

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
     <SOAP_Customer_Metadata_CALLResponse xmlns="http://BCE/Customer_Metadata_WS.tws"> 
     <oMetaDataID> 
      <ocrStatus>Failed</ocrStatus> 
      <guid>123456</guid> 
      <docType>03</docType> 
      <docDescription>South African ID</docDescription> 
      <surname>Choudhary</surname> 
      <fullName>Kanika</fullName> 
      <idNumber>KANJANDHS293</idNumber> 
      <dateOfBirth>22091945</dateOfBirth> 
      <dateIssued>01012016</dateIssued> 
      <countryOfBirth>India</countryOfBirth> 
      <idType>ID</idType> 
      <gender>F</gender> 
     </oMetaDataID> 
     <oMetaDataPOA> 
      <ocrStatus>Passed</ocrStatus> 
      <surname>Choudhary</surname> 
      <idNo>12345</idNo> 
      <address1>abc def</address1> 
     </oMetaDataPOA> 
     <oResubmission>No</oResubmission> 
     <oCASASequenceNo>1234578</oCASASequenceNo> 
     <oTypeOfCustomer>New</oTypeOfCustomer> 
     </SOAP_Customer_Metadata_CALLResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 

Groovy中使用如下代码脚本一步步测试:

holder.getNodeValue("//idNumber") 

回答

0

正如@ har07回答,您可以定义一个命名空间前缀,然后在的XPath使用它。然而SOAPUIXmlHolder支持通配符*的命名空间,所以你可以简单地使用它在你的的XPath

holder.getNodeValue("//*:idNumber") 

编辑

使用holder.getNodeValue("//*:oMetaDataID/ocrStatus")如您在评论做的问题是,你”重新丢失第二个元素的名称空间,在这里,您还可以使用*通配符作为:

holder.getNodeValue("//*:oMetaDataID/*:ocrStatus") 
+0

谢谢@albciff。这个工作得很好。 bur当我试图通过使用holder.getNodeValue(“// *:oMetaDataID/ocrStatus”)访问“oMetaDataID”标签下的“ocrStatus”时,我没有得到任何东西。请帮忙 – Bhushan

1

这是可能的,因为XML具有默认命名空间

xmlns="http://BCE/Customer_Metadata_WS.tws" 

在该名称空间中考虑了在SOAP_Customer_Metadata_CALLResponse之内的所有没有前缀的元素,包括idNumber。要选择默认名称空间中的元素,您需要将前缀映射到默认名称空间URI,并在XPath中使用该前缀。例如,如果注册的前缀是d//d:idNumber(我不知道groovy,但this post可能会有用)。

等效的,纯的XPath,方法是使用XPath函数local-name()namespace-uri()组合:

//*[local-name()='idNumber' and namespace-uri()='http://BCE/Customer_Metadata_WS.tws']