我正在编写一个泛型函数,它试图获取从cts.search
函数返回的元素 node 的命名空间.我面临的挑战是您无法获得元素的命名空间.我试着用node.getAttributeNode("xmlns")
,但这也不起作用.文档中似乎没有支持Java脚本中的XML命名空间的函数
以下是我正在使用的解决方案.
'use strict';
const DB_ID = xs.unsignedLong("5944350410045404402") //Meters database
const INVOKE_OPTS = {"database": xdmp.database()}
const getRoots = (bdone,iterations,filters,output)=>{
let filterQuery = filters.map((filter)=>{
return cts.notQuery(cts.documentRootQuery(filter))
})
let rootDoc = xdmp.invokeFunction(()=>fn.subsequence(cts.search(cts.andQuery([])),1,1),INVOKE_OPTS)
let isEmpty = rootDoc != null ? true:false
if(isEmpty != true) {
return output
} else {
//Advance path the document node
let node = rootDoc.toArray()[0].xpath("/node()").toArray()[0]
let nodeKind = node.nodeKind
let baseUri = node.baseUri
let nodeName = xs.QName("foo")
let nodeNs = ""
switch(nodeKind) {
case "element" :
nodeName = node.nodeName
nodeNs = node.getAttributeNode("xmlns")
break;
case "object-node" :
case "array-node" :
nodeName = "json"
break
}
let nodePath = xdmp.path(node)
return {
"kind" : nodeKind,
"ns" : nodeNs,
"name" : nodeName,
"path" : nodePath
}
}
}
getRoots(false,0,[],[])