PatchBuilderPlan.prototype.replaceInsertChild( parentPath as String, pathToReplace as String, content as Node ) as PatchBuilderPlan
Replace a child if it exist, or insert if it does not exist.
Parameters | |
---|---|
parentPath | The parent path to insert/replace. |
pathToReplace | The path to insert/replace which is relative to parent-path. |
content | The new content. |
'use strict'; declareUpdate(); const op = require('/MarkLogic/optic'); const docDescriptors = [{uri: '/test.xml',doc:xdmp.unquote("<doc><entry><action>write4</action></entry></doc>")}, {uri: '/test2.xml',doc:xdmp.unquote("<doc><entry></entry></doc>")}] op.fromDocDescriptors(docDescriptors) .patch(op.col('doc'), op.patchBuilder('/doc') .replaceInsertChild('entry', 'action',xdmp.unquote("<action>write</action>")) ) .write() .result();