簡體   English   中英

Xpath:僅返回具有內容的節點

[英]Xpath: return only nodes with content

當我使用此xpath查詢時:

>xpath //XmlFeed/ProductList/Product/ProductGroup

返回1000個結果,這是正確的。 但是,在1000個結果中,有700個是零元素,例如:

<ProductGroup xsi:nil="true"/>

其余的確實有數據:

<ProductGroup>
<ID>100</ID>
<Description>Something cool</Description>
</ProductGroup>

是否可以更改查詢,以便僅獲得非零結果?

您可以添加謂詞以僅獲取具有子元素的ProductGroup

//XmlFeed/ProductList/Product/ProductGroup[*]

像這樣:

//XmlFeed/ProductList/Product/ProductGroup[*!='']

這一結果為您提供了完全沒有xsi:nil屬性的所有結果(順便說一句,它不檢查xsi:nil值本身)。 但這可能適合您的問題。

//XmlFeed/ProductList/Product/ProductGroup[not(@xsi:nil)]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM