【问题标题】: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,否则使用 XQuery 和 XPath 返回 false?
【发布时间】:2020-11-20 13:08:04
【问题描述】:

我想遍历 xml 文档中的每个节点,如果节点等于某个字符串值,则返回 true,否则返回 false。输出应该类似于:

是的 错误的 错误的 真的 是的

True 是节点名称与字符串匹配的地方。

谢谢。

【问题讨论】:

  • 请编辑您的问题并添加您的 xml 的代表性示例,以及您要测试的字符串。

标签: xml xpath xquery


【解决方案1】:

我将您的问题理解为//*/(. instance of element(foo)for $el in //* return $el instance of element(foo)(其中foo 将是您要查找的元素的名称)。

但是,您不能将其作为字符串传递,因为您需要 declare $name as xs:string external := 'foo'; //*/(local-name() = $name)

【讨论】:

    【解决方案2】:

    如果我们从字面上理解你的问题,那就是

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

    但我怀疑“节点”实际上是指元素(在这种情况下是 //*),并且“匹配”可能是指“=”以外的其他东西。

    【讨论】:

      猜你喜欢
      • 2021-03-21
      • 1970-01-01
      • 2017-07-25
      • 1970-01-01
      • 2022-12-04
      • 2021-09-08
      • 2018-09-24
      • 1970-01-01
      • 2017-11-17
      相关资源
      最近更新 更多