6

I have couple of documents on which xdmp:node-replace() over certain elements doesnot work. There are some other set of documents which are almost similar to the ones that has problem but xdmp:node-replace works perfectly fine on them. Tried all possibilities that could have gone wrong but in vain. Read some where that xdmp:node-replace function does not work on 'in memory elements'.

So in order to verify whether the issue is with 'in memory elements', I want to know what exactly it is.

Any light on it would be of great help

Sofia
  • 771
  • 1
  • 8
  • 22
NitZRobotKoder
  • 1,046
  • 8
  • 44
  • 74

3 Answers3

6

Anything constructed within a query is an in-memory element. For example this XQuery yields an in-memory element:

<test/>

Some function calls also return in-memory elements: xdmp:unquote is an obvious example. Any node that doesn't come from the current database will be treated as an in-memory node.

This query yields a database element (if it exists), which could be modified using xdmp:node-replace:

doc('fubar')/test

This is a typical in-memory update error:

xdmp:node-replace(<x/>, <y/>)

With MarkLogic 6.0-1.1, the error code is XDMP-UPCONSTNODES.

mblakele
  • 7,782
  • 27
  • 45
6

If you want to update in-memory nodes as if they were in the database by using similar function calls, there's a utility library that does that:

https://github.com/marklogic/commons/tree/master/memupdate

The main library also ships with MarkLogic Server under App Services:

appservices/utils/in-mem-update.xqy

hunterhacker
  • 6,378
  • 1
  • 14
  • 11
  • 1
    For a slightly more optimized version of that library, see: https://github.com/ryanjdew/XQuery-XML-Memory-Operations – grtjn May 22 '17 at 12:30
2

If your working with in memory elements import the following module

import module namespace mem = "http://xqdev.com/in-mem-update" at "/MarkLogic/appservices/utils/in-mem-update.xqy";

Instead of using xdmp:node-replace you can use mem:node-replace(<x/>, <y/>)

Nikunj Vekariya
  • 833
  • 5
  • 19