在现有元素节点中添加新属性

Adding new attribute in an existing element node

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

<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>

您可以使用 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!