2016-05-06 52 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']