在现有元素节点

时间:2017-09-21 16:02:01

标签: marklogic

我需要语法在现有元素节点中添加新属性。 样品

<version id="1" version-status="active">
<source/>
<file-text>ABC</file-text>
.
.
.
<file-date>07/06/2017</file-date>
</version>

我希望通过将其余数据保留在版本中来将新属性(myAttribute)添加到版本元素。 例如

<version id="1" status="active" myAttribute="true">
<source/>
<file-text>ABC</file-text>
.
.
.
<file-date>07/06/2017</file-date>
</version>

1 个答案:

答案 0 :(得分:2)

您可以使用xdmp:node-insert-child(),它也适用于属性:

xdmp:document-insert("/test.xml", <version id="1" version-status="active">
  <source/>
  <file-text>ABC</file-text>
  ...
  <file-date>07/06/2017</file-date>
</version>)

;

xdmp:node-insert-child(doc("/test.xml")/version, attribute myAttribute { "true" })

;

doc("/test.xml")

HTH!