2013-10-01 102 views
0

的標記元素的值我有以下XML查詢:如何選擇所有給定節點下的標籤沒有得到在XML

 <return> 
     <code>success</code> 
     <message/> 
     <deal> 
      <checksum>203591</checksum> 
      <documentID>21783</documentID> 
      <dealStatus>P</dealStatus> 
      <financing> 
       <financeType>L</financeType> 
       <term>32</term> 
      </financing> 
      <options> 
       <disclosureType/> 
       <frontBackFlag>P</frontBackFlag> 
       <hardSoftFlag>M</hardSoftFlag> 
       <optionCode>TO</optionCode> 
       <optionDescription>QAfhggddate DOCID 219</optionDescription> 
       <optionOrigin>xxx</optionOrigin> 
       <optionPrice> 
       <optionPricingType>INVIICE</optionPricingType> 
       <price>111.99</price> 
       </optionPrice> 
       <optionPrice> 
       <optionPricingType>RETAIL</optionPricingType> 
       <price>2.99</price> 
       </optionPrice> 
       <optionResidualAmount>3.99</optionResidualAmount> 
       <residualTableAmount>0.00</residualTableAmount> 
       <residualTableFlag>N</residualTableFlag> 
       <satisfiedDate>2012-05-08T00:00:00-06:00</satisfiedDate> 
      </options> 
     </deal> 
    </return> 

我需要把一個檢查點,以驗證上述反應只有場在我們的規格中提到。例如。 optionPrice應該只有optionPricingType &價格標籤。所以如何編寫xpath或xqery來獲取optionPrice下的所有標籤而沒有它們的值。

我使用SOAP UI把斷言

+0

success XXX 發票 111.99 零售 222。99 user2833969

回答

1

接下來的XPath將從optionPrice提取節點名稱:

/return/deal/options/optionPrice/*/local-name() 
2
  1. 據了SoapUI的 「Functional Testing」 的文件,您可以就斷言架構遵從。我建議使用此工具來驗證響應是否符合您的規範。如果你想/不得不使用XPath,這裏有一些想法。假設XPath 2.0在SoapUI中可用,「XPath和XQuery Match斷言都使用支持該領域大部分最新標準的Saxon XPath/XQuery處理器。」參考:Validating XML Messages

(#2待續......)您可以測試已知元素的存在(所有預期成果將是真實的):

boolean(/return) 
boolean(/return/code) 
boolean(/return/deal) 
boolean(/return/deal/checksum) 

等。注意,這不測試元素排序,這對您而言可能是重要的,也可能不重要。

可以測試沒有未知的元素的(預期的結果將是真實的):

min(for $elName in //*/local-name() return $elName = ('return','code','message','deal','checksum','documentID','dealStatus','financing','financeType','term','options','disclosureType','frontBackFlag','hardSoftFlag','optionCode','optionDescription','optionOrigin','optionPrice','optionPricingType','price','optionPrice','optionPricingType','price','optionResidualAmount','residualTableAmount','residualTableFlag','satisfiedDate')) 

注意事項使用min在布爾值列表的黑客有效執行邏輯,並通過傳球每個單獨的標籤名稱測試結果。

您可以通過XPath斷言進行各種其他抽查,但如果可能的話,儘量使用#1中提到的模式一致性設施。

相關問題