如何替换 marklogic 中特定元素的属性文本
How do i replace attribute text for a particular element in marklogic
所以这是我的 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
我也尝试过替换整个元素,但它太麻烦了,而且会弄乱元素的命名空间。
所以我们可以使用以下方法单独更新属性文本:
xdmp:node-replace(fn:doc("custom_1.xml")/customer/productsPurchased/@count, attribute { "count" } { "4" } )
attribute { "count" }
表示属性名称为"count"的属性节点,就像我们有text { "some text" }
文本节点一样。
所以这是我的 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
我也尝试过替换整个元素,但它太麻烦了,而且会弄乱元素的命名空间。
所以我们可以使用以下方法单独更新属性文本:
xdmp:node-replace(fn:doc("custom_1.xml")/customer/productsPurchased/@count, attribute { "count" } { "4" } )
attribute { "count" }
表示属性名称为"count"的属性节点,就像我们有text { "some text" }
文本节点一样。