[英]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" }
文本节点一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.