Loading TOC...

MarkLogic 12 Product Documentation
PatchBuilderPlan.prototype.replace

PatchBuilderPlan.prototype.replace(
   path as String,
   content as Node
) as PatchBuilderPlan

Summary

Replace a node with another node.

Parameters
path The path to replace.
content The new content.

Example

'use strict';
declareUpdate();
const op = require('/MarkLogic/optic');
const docDescriptors = [{uri: '/optic/update/write4.xml',doc:xdmp.unquote("<doc><action>write4</action></doc>")},
                        {uri:  '/optic/update/write5.xml',doc:xdmp.unquote("<doc><action>write4</action></doc>")}]
op.fromDocDescriptors(docDescriptors)
  .patch(op.col('doc'),
         op.patchBuilder('/doc')
           .replace("action",xdmp.unquote("<newAction>new</newAction>"))
        )
.write()
.result();

/* This returns doc as

{
"doc": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc><newAction>new</newAction></doc>", 
"uri": "/optic/update/write4.xml"
},
{
"doc": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<doc><newAction>new</newAction></doc>", 
"uri": "/optic/update/write5.xml"
}

 */
  

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