簡體   English   中英

如何遍歷 xml 文件中的每個節點並在節點名稱與字符串匹配時返回 true,否則使用 XQuery 和 XPath 返回 false?

[英]How to go through each node in a xml file and return true if the name of the node matches a string and false otherwise using XQuery and XPath?

我想遍歷 xml 文檔中的每個節點,如果節點等於某個字符串值則返回 true,否則返回 false。 輸出應類似於:

真假假真真

True 是節點名稱與字符串匹配的地方。

謝謝。

如果我們從字面上理解你的問題,那就是

(//node()) ! (if (. = 'a certain string value') then 'True' else 'False'

但我懷疑“節點”實際上是指元素(在這種情況下它是//* ),並且“匹配”可能指的是“=”以外的其他東西。

我將您的問題理解為//*/(. instance of element(foo)for $el in //* return $el instance of element(foo) (其中foo將是您要查找的元素的名稱)。

但是,您不能將其作為字符串傳入,為此您需要將declare $name as xs:string external := 'foo'; //*/(local-name() = $name) declare $name as xs:string external := 'foo'; //*/(local-name() = $name) .

暫無
暫無

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

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