![](/img/trans.png)
[英]XQuery sequence equivalent in MarkLogic Server-Side JavaScript
[英]What is the server side javascript equivilant to xpath for xquery
鑒於這樣的集合:
collection : [
'doc1.json' : {
someXPath : [
{ expression : 'a' },
{ expression : 'b' },
{ expression : 'c' },
],
otherLargeObject : [ ... ]
},
'doc2.json' : {...},
'doc3.json' : {...}
]
使用Xquery我可以選擇集合的子節點,如下所示:
fn:doc()//someXPath/expression/text()
導致這樣的事情:
[ 'a', 'b', 'c', ... ]
上面的語法簡潔,結果只包含我想要的數據。
使用Javascript我會嘗試以下內容:
var results = [];
for (var doc of fn:doc()) {
if (doc.someXPath) {
results.push(doc.someXPath.map(function (x) {
return x.expression;
})
}
}
javascript代碼冗長而不是多功能。 xquery示例匹配具有不同嵌套級別的其他文檔結構,而無需額外條件。
doc迭代器是在內存中檢索整個文檔還是只檢索被訪問的部分? 例如,在JavaScript版本中將otherLargeObject加載到內存中? javascript版本和xquery版本一樣高效嗎?
是否有類似以下內容?
var result = [];
for (var justTheNodesIWant in fn:doc()('//someXPath/expression/text()') {
result.concat(justTheNodesIWant);
}
result; // ['a', 'b', 'c', ... ]
是否有使用服務器端javascript實現xquery結果和性能的等效方法?
以下將工作:
var results = [];
for (var exp of xdmp.xqueryEval('fn:doc()/someXPath/expression')) {
results.push(exp);
}
results
其缺點是語言的混合,包括在代碼中嵌入代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.