2016-04-20 322 views
1

我無法爲soapui中的下面的xml獲取xpath值「MatchFound」。 我正在嘗試屬性傳遞功能。無法從soapui獲取xpath值

我嘗試以下XPath:

declare namespace ns0='http://KYC/'; 
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/'; 
/soapenv:Envelope/soapenv:Body/BarclaysCustomerValidationResponse/oCasaDetailByRefNoDetails/oCasaStatusByRefNoDetails/oRiskProfileClientData/oGetFraudInformationData/oAddressVerificationDetails/ns0:matchedFound 

XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
     <BarclsCustomerValidationResponse xmlns="http://BHKYC/BarclaysCustomerValidation.tws"> 
     <oCasaByIdNoDetails> 
      <ns0:casaByIdNoResults xmlns:ns0="http://KYC"> 
       <ns0:item/> 
      </ns0:casaByIdNoResults> 
     </oCasaByIdNoDetails> 
     <oCasaDetailByRefNoDetails/> 
     <oCasaStatusByRefNoDetails/> 
     <oRiskProfileClientData/> 
     <oGetFraudInformationData/> 
     <oAddressVerificationDetails> 
      <ns0:enquiryid xmlns:ns0="http://KYC">51644325</ns0:enquiryid> 
      <ns0:enquiryresultid xmlns:ns0="http://KYC">52146422</ns0:enquiryresultid> 
      <ns0:matchedFound xmlns:ns0="http://KYC">false</ns0:matchedFound> 
      <ns0:numberOfMatches xmlns:ns0="http://KYC">1</ns0:numberOfMatches> 
      <ns0:firstMatchUpdatedDate xmlns:ns0="http://KYC">2016-03-31</ns0:firstMatchUpdatedDate> 
      <ns0:secondMatchUpdatedDate xmlns:ns0="http://KYC"/> 
      <ns0:mostRecentAddressIsMatched xmlns:ns0="http://KYC">false</ns0:mostRecentAddressIsMatched> 
     </oAddressVerificationDetails> 
     <oCasaPS/> 
     <pid>21691</pid> 
     </BarclsCustomerValidationResponse> 
    </soapenv:Body> 
</soapenv:Envelope> 
+0

你申報NS0命名空間URI包含一個結尾'/',該文檔中命名空間不 –

+0

以下可以成爲你的XPath 「// BarclsCustomerValidationResponse/oAddressVerificationDetails/NS0:matchedFound」。最佳做法是屏蔽名稱空間。現在看起來像「// BarclsCustomerValidationResponse/oAddressVerificationDetails/*:matchedFound」 – Ramu

回答

0

這裏有一些問題:

  • 空間URI分配給ns0在XPath/XQuery不匹配
  • 的XML已經在BarclsCustomerValidationResponse元素聲明默認命名空間 XML中的一個。這意味着BarclsCustomerValidationResponse和所有沒有前綴的後代元素都在同一個命名空間中。您需要聲明另一個前綴,它映射到默認的命名空間URI,並在XPath相應使用前綴

下面的工作對我來說:

declare namespace ns0='http://KYC'; 
declare namespace d='http://BHKYC/BarclaysCustomerValidation.tws'; 
declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/'; 

/soapenv:Envelope 
/soapenv:Body 
/d:BarclsCustomerValidationResponse 
/d:oAddressVerificationDetails 
/ns0:matchedFound 

演示:http://www.xpathtester.com/xquery/b8f1f1e9e0c64af37a2e398d5b911569

0

BarclaysCustomerValidationResponse是在命名空間http://BHKYC/BarclaysCustomerValidation.tws,所以你的XPath表達式/BarclaysCustomerValidationResponse/無法找到它。它的子元素也是如此,除非它們有一個特定的名稱空間前綴,如ns0:

0

剛爲了在SoapUI中讀取XML,你不需要打擾命名空間。正如您發現的那樣,它們使XPath不必要的複雜化。對於你的情況,這樣簡單的事情就足夠了。

//*:matchedFound