2015-04-03 31 views
0

我從我打來的服務中得到這個響應。我希望在Soap-UI中寫一個斷言來驗證<Result>標記的值。如何找到此XML中的<Result>標記的XPath?

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> 
    <s:Body> 
     <ServiceResponse> <!--Issue happens here when xmlns attribute is present--> 
      <ServiceResult xmlns:a="http://schemas.datacontract.org/2004/07/services.api.DataContracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
       <AdditionalInfo i:nil="true"/> 
       <ErrorMessage/> 
       <ErrorMessageId i:nil="true"/> 
       <ErrorMessages xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/> 
       <InternalId>0</InternalId> 
       <RecordsAffected>0</RecordsAffected> 
       <Result>false</Result> 
       <WarningMessages xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/> 
       <a:ReturnBase> 
       </a:ReturnBase> 
      </ServiceResult> 
     </ServiceResponse> 
    </s:Body> 
</s:Envelope> 

我用Xpath Testing tool online找到正確的路徑。當我刪除<ServiceResponse>標記上的xmlns屬性時,XPATH將按預期工作。但是,當<ServiceResponse>標籤上有xmlns="http://schema.Services"時,XPath無法返回項目。

我也嘗試在Notepad ++中用XML Tools Plugin找到它,當我有<ServiceResponse xmlns="http://schema.Services">時,它會拋出異常。

我該如何着手在soap-UI中編寫這個斷言?

+0

您錯過了爲選定的Result元素提供XPath表達式,這是有問題的。可能的原因是您沒有正確指定要調用的XPath處理器的命名空間綁定來評估XPath表達式。你正在使用哪種XPath處理器?請編輯問題並提供這些重要的缺失信息。 – 2015-04-04 02:42:00

回答

0

XML名稱空間的概念是,您可以爲它們分配任意前綴。

所以,如果你的XML使用默認的命名空間,你可以做一個前綴是:

declare namespace s='http://schemas.xmlsoap.org/soap/envelope/'; 
declare namespace serv='http://schema.Services'; 
/s:Envelope/s:Body/serv:ServiceResponse/serv:ServiceResult/serv:Result[. = 'false'] 
0

了SoapUI使用撒克遜的XPath/XQuery處理,所以得到了XPath 2.0。 XPath 2.0的好處之一是命名空間通配符,因此您可以這樣做:

/*:Envelope/*:Body/*:ServiceResult