简体   繁体   English

什么是服务器端javascript等效于xpath的xpath

[英]What is the server side javascript equivilant to xpath for xquery

Given a collection like this: 鉴于这样的集合:

collection : [
    'doc1.json' : {
       someXPath : [
           { expression : 'a' },
           { expression : 'b' },
           { expression : 'c' },
       ],
       otherLargeObject : [ ... ]
    },
    'doc2.json' : {...},
    'doc3.json' : {...}
]

Using Xquery I can select child nodes of the collection as follows: 使用Xquery我可以选择集合的子节点,如下所示:

fn:doc()//someXPath/expression/text() 

resulting in something this: 导致这样的事情:

[ 'a', 'b', 'c', ... ]

The above syntax is concise and the result only includes the data I want. 上面的语法简洁,结果只包含我想要的数据。

Using Javascript I would try the following: 使用Javascript我会尝试以下内容:

var results = [];
for (var doc of fn:doc()) {
    if (doc.someXPath) {
        results.push(doc.someXPath.map(function (x) {
            return x.expression;
        })
    }
}

The javascript code is verbose and not as versatile. javascript代码冗长而不是多功能。 The xquery example matches other document structures with different levels of nesting without the need for extra conditions. xquery示例匹配具有不同嵌套级别的其他文档结构,而无需额外条件。

Does the doc iterator retrieve the entire document in memory or just the parts that are accessed? doc迭代器是在内存中检索整个文档还是只检索被访问的部分? eg is otherLargeObject loaded into memory in the javascript version? 例如,在JavaScript版本中将otherLargeObject加载到内存中? Is the javascript version as efficient as the xquery version? javascript版本和xquery版本一样高效吗?

Is something like the following possible? 是否有类似以下内容?

var result = [];
for (var justTheNodesIWant in fn:doc()('//someXPath/expression/text()') {
    result.concat(justTheNodesIWant);
}
result;  // ['a', 'b', 'c', ... ]

Is there an equivalent way to achieve the xquery result and performace using server side javascript? 是否有使用服务器端javascript实现xquery结果和性能的等效方法?

The below will work: 以下将工作:

var results = [];

for (var exp of  xdmp.xqueryEval('fn:doc()/someXPath/expression')) {
  results.push(exp);
}

results

The downside of that is the mixing of languages, including embedding code in a string. 其缺点是语言的混合,包括在代码中嵌入代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM