我正在编写一个泛型函数,它试图获取从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,[],[])

推荐答案

XML node 可以使用namespaceURI

nodeNs = node.namespaceURI

您还可以使用XPath和namespace-uri()方法:

nodeNs = node.xpath("namespace-uri(.)")

Javascript相关问答推荐

如何使用JavaScript用等效的功能性HTML替换标记URL格式?

如何获取转换字节的所有8位?

有什么(最佳)方法可以从模块中获取脚本模块的多姆元素吗?

微软Edge Select 间隙鼠标退出问题

react/redux中的formData在expressjs中返回未定义的req.params.id

Plotly热图:在矩形上zoom 后将zoom 区域居中

如何将Map字符串,布尔值转换为{key:string;value:bo布尔值;}[]?<>

如何添加绘图条形图图例单击角形事件

获取Uint8ClampedArray中像素数组的宽度/高度

正则表达式,允许我匹配除已定义的子字符串之外的所有内容

从另一个数组中的对应行/键值对更新数组中的键值对对象

如何 for each 输入动态设置输入变更值

如何在Java脚本中对列表中的特定元素进行排序?

MongoDB通过数字或字符串过滤列表

TypeORM QueryBuilder限制联接到一条记录

如何在Reaction中设置缺省值, Select 下拉列表,动态追加剩余值?

在范围数组中查找公共(包含)范围

如何创建一个for循环,用于计算仪器刻度长度并将其放入一个HTML表中?

:host::ng-Deep不将样式应用于material 复选框

如何使用Angular JS双击按钮