奇怪的错误MarkLogic搜索节点

问题描述 投票:0回答:1

我在QueryConsole中有问题

当我尝试运行这个:

xquery version "1.0-ml";
declare namespace link="http://www.xbrl.org/2003/linkbase";
declare namespace bd-alg="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-algemeen";
declare namespace bd-bedr="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-bedrijven";
declare namespace bd-bedr-tuple="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-bedr-tuples";
declare namespace bd-dim-mem="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-domain-members";
declare namespace bd-dim-dim="http://www.nltaxonomie.nl/nt11/bd/20161207/validation/bd-axes";
declare namespace xbrldi="http://xbrl.org/2006/xbrldi";
declare namespace xbrli="http://www.xbrl.org/2003/instance";
declare namespace iso4217="http://www.xbrl.org/2003/iso4217";
declare namespace xlink="http://www.w3.org/1999/xlink";

let $factValues :=
  for $doc in /xbrli:xbrl
      let $factValue := $doc//xs:QName("bd-bedr:WageTaxDebt")
      let $docId := $doc//xbrli:identifier/text()
      where $docId eq "11"
            return $factValue/text()

return $factValues

引号之间的字符串是来自仅给出字符串的输入中的字符串

我收到此错误:

[1.0-ml] XDMP-NOTANODE: (err:XPTY0019) $factValue/text() -- "bd-bedr:WageTaxDebt" is not a node
Stack Trace
At line 19 column 21:
In xdmp:eval("xquery version &quot;1.0-ml&quot;;&#10;&#10;declare namespace li...", (), <options xmlns="xdmp:eval"><database>11967107844575880929</database>...</options>)
$doc := fn:doc("document76.xml")/xbrli:xbrl
$factValue := ("bd-bedr:WageTaxDebt", "bd-bedr:WageTaxDebt", "bd-bedr:WageTaxDebt", ...)
$docId := fn:doc("document76.xml")/xbrli:xbrl/xbrli:context/xbrli:entity/xbrli:identifier/text()
17. let $docId := $doc//xbrli:identifier/text()
18. where $docId eq "11"
19. return $factValue/text()
20. 
21. return $factValues

我知道字符串不是一个节点,但不应该转换为QName来解决这个问题吗?

有谁知道我做错了什么,谢谢你提前!

xml xquery marklogic
1个回答
7
投票

正如你已经想到的那样,你不能写:

let $factValue := $doc//xs:QName("bd-bedr:WageTaxDebt")

XPath表达式更好地编写为:

let $factValue := $doc//bd-bedr:WageTaxDebt

你是在动态XPath之后,这让它变得有点棘手。使用普通XPath,您可以:

let $factValue := $doc//*[name() eq xs:QName("bd-bedr:WageTaxDebt")]

但这可能非常慢,特别是如果您的XML文档很大。一种更高效的方式可能是:

let $factValue := xdmp:value("$doc//" || xs:QName("bd-bedr:WageTaxDebt"))

但是,这会带来代码注入的风险,因此您必须仔细验证输入,例如将转换保持为xs:QName

但是,最佳方法可能是使用xdmp:unpath

let $factValue := xdmp:unpath("$doc//" || "bd-bedr:WageTaxDebt")

HTH!

© www.soinside.com 2019 - 2024. All rights reserved.