使用 MarkLogic 的补丁功能替换文本内容和属性

Replacing both text content and an attribute using MarkLogic's patch functionality

我正在尝试使用 Marklogic 8 的部分更新(补丁)功能在同一请求中更改元素的属性和元素的文本内容。

如果我有这样的文档:

<root>
    <foo a1="1" a2="2" a3="3" a4="4">text content</foo>
</root>

我尝试使用以下方式更新它:

<rapi:patch xmlns:rapi="http://marklogic.com/rest-api">
    <rapi:replace select="/root/foo">replace text</rapi:replace>
    <rapi:replace select="/root/foo/@a3">replace a3</rapi:replace>
</rapi:patch>

我得到 XDMP-CONFLICTINGUPDATES。文档提到 'The selected node cannot be the target of any other operation in the patch. The ancestor of the selected node may not be modified by a delete, replace, or replace-insert operation in the same patch.' 我猜我 运行 在这里,因为我选择的是元素而不是直接选择文本节点。

使用 xquery,我可以像这样指定一个文本节点进行替换:

xdmp:node-replace(fn:doc($uri)/root/foo/text() , text{ "new text" } )

但是,我似乎不能用补丁来做到这一点。使用 /root/foo/text() 会导致有关无效路径的错误,因为补丁需要可用于定义索引的路径表达式。

有没有办法在同一个请求中更改这两个值?

由于(如您所述)您不能具体引用文本元素,我认为您需要替换整个元素:

<rapi:patch xmlns:rapi="http://marklogic.com/rest-api">
  <rapi:replace select="/root/foo">
    <foo a1="1" a2="2" a3="new 3" a4="4">new text</foo>
  </rapi:replace>
</rapi:patch>

元素是属性的父元素,因此无法避免冲突更新。