我需要使用XML表的MarkLogic替换现有节点。如何替换MarkLogic中的节点?
我不使用查询控制台,而是将所有代码写入.sjs文件。当我经历了MarkLogic文档中给出的步骤时,它会抛出一些错误。
示例代码:
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
我不得不“从”更改标签并替换为“发件人”,即。预期输出:
<note>
<to>Tove</to>
<sender>Jani</sender>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Java代码:
上传SJS从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();
变换应用从MarkLogic读取数据之前的变换。在数据库中的实际数据将不会被更新
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代码:
declareUpdate();
var n = new NodeBuilder();
node = n.addElement("sender", "Jani").toNode();
xdmp.nodeReplace(
cts.doc("/example.xml").xpath("/note/from"),
node
);
错误:
Operation not allowed on the currently executing transaction with identifier declareUpdate
请发布_what_您尝试过,以及它如何失败(确切的错误消息,错误的输出,...)。 – 2015-03-31 12:26:12
这是一个我想: xdmp:文档插入(! “/的example.xml”,托弗 贾尼 提醒 这个周末不要忘记我 ); xdmp:nodeReplace(doc(“/ example.xml”)/ note/from, Jack ); –
2015-03-31 12:39:12
错误: HTTP状态500 - 请求处理失败;嵌套异常是com.marklogic.client.FailedRequestException:本地消息:config/transforms写入失败:内部服务器错误。服务器消息:JS的JavaScript:托芙 贾尼 提醒 不要 - 错误运行的JavaScript要求:语法错误:意外标记<。有关更多详细信息,请参阅MarkLogic服务器错误日志。 –
2015-03-31 12:41:25