Loading TOC...

MarkLogic Server 11.0 Product Documentation
PatchBuilderPlan.prototype.replaceInsertChild

PatchBuilderPlan.prototype.replaceInsertChild(
   parentPath as String,
   pathToReplace as String,
   content as Node
) as PatchBuilderPlan

Summary

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.

Example

'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();

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.