I need to replace the existing node with the new name using MarkLogic of an XML sheet.
I don't use Query Console and I write all my code in .sjs file. When I have gone through the steps given in MarkLogic docs, it is throwing some errors.
Sample code:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
I have to change tag "from" and replace it as "sender", ie. expected output:
<note>
<to>Tove</to>
<sender>Jani</sender>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Java Code:
uploading sjs transform from java
DatabaseClient client = DatabaseClientFactory.newClient(IP, 8000,
DATABASE_NAME, USERNAME, PWD, Authentication.DIGEST);
// get transform mgr
TransformExtensionsManager transMgr = client.newServerConfigManager()
.newTransformExtensionsManager();
FileInputStream transStream = null;
try {
transStream = new FileInputStream(path);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStreamHandle ipStreamHandle = new InputStreamHandle(transStream);
transMgr.writeJavascriptTransform(JS_TRANSFORM_NAME, ipStreamHandle);
client.release();
Applying the transform before reading the data from MarkLogic. The actual data in database won't be updated
ServerTransform transform = new ServerTransform(transformName);
DatabaseClient client = DatabaseClientFactory.newClient(IP, 8000,
DATABASE_NAME, USERNAME, PWD, Authentication.DIGEST);
JSONDocumentManager docMgr = clientNew.newJSONDocumentManager();
InputStreamHandle handle = new InputStreamHandle();
docMgr.read("/" + uri + JSON_EXT, handle, transform);
String document = handle.toString();
clientNew.release();
return document;
.sjs code:
declareUpdate();
var n = new NodeBuilder();
node = n.addElement("sender", "Jani").toNode();
xdmp.nodeReplace(
cts.doc("/example.xml").xpath("/note/from"),
node
);
Error:
Operation not allowed on the currently executing transaction with identifier declareUpdate