【问题标题】:How do i replace attribute text for a particular element in marklogic如何替换marklogic中特定元素的属性文本
【发布时间】:2019-10-16 11:42:04
【问题描述】:

这就是我的custom_1.xml 的样子:

<customer>
    <name>Customer 1</name>
    <productsPurchased count="2">
        <product>one</product>
        <product>two</product>
    </productsPurchased>
</customer>

我想将属性 count="2" 替换为具有值 4,因此 xml 将变为:

<customer>
    <name>Customer 1</name>
    <productsPurchased count="4">
        <product>one</product>
        <product>two</product>
    </productsPurchased>
</customer>

如何使用xdmp:node-replace 实现这一目标?我试过使用:

xdmp:node-replace(fn:doc("custom_1.xml")/customer/productsPurchased/@count, text { "4" } )

但这会报错:attribute nodes cannot be replaced with text nodes

我也尝试过替换整个元素,但它太麻烦了,而且会弄乱元素的命名空间。

【问题讨论】:

    标签: xquery marklogic


    【解决方案1】:

    所以我们可以单独使用以下来更新属性文本:

    xdmp:node-replace(fn:doc("custom_1.xml")/customer/productsPurchased/@count, attribute { "count" } { "4" } )
    

    attribute { "count" } 表示属性名称为“count”的属性节点,就像我们有 text { "some text" } 文本节点一样。

    【讨论】:

      猜你喜欢
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多