声明命名空间的 XQuery 语法:[XPST0081] 没有为“text:p”声明命名空间

Thu*_*fir 2 xml xpath xquery exist-db basex

为Libre Office声明命名空间的语法是什么?需要声明什么特定命名空间?

thufir@dur:~/fods/flwor$ 
thufir@dur:~/fods/flwor$ basex text.xq 
Stopped at /home/thufir/fods/flwor/text.xq, 3/14:
[XPST0081] No namespace declared for 'text:p'.
thufir@dur:~/fods/flwor$ 
thufir@dur:~/fods/flwor$ cat text.xq 

for $foo  in db:open("foo")
return $foo//text:p

thufir@dur:~/fods/flwor$ 
Run Code Online (Sandbox Code Playgroud)

当然,$foo单独返回可以很好地返回整个文档。

我是否还需要将命名空间存储在本地文件中?或者,只需添加类似以下内容:

declare namespace type4="http:///de/tudarmstadt/ukp/dkpro/core/api/segmentation/type.ecore";

Leo*_*ler 5

您在查询中使用的每个命名空间前缀也必须在查询中声明。根据您的情况,您可以添加一行

declare namespace text="urn:oasis:names:tc:opendocument:xmlns:text:1.0";
Run Code Online (Sandbox Code Playgroud)

在顶部修复您的查询。

由于命名空间前缀(text在您的例子中)只是对关联命名空间 URI 的引用,因此它不必与 XML 文档中的前缀匹配。以下查询 100% 等效:

declare namespace whatever="urn:oasis:names:tc:opendocument:xmlns:text:1.0";

for $foo in db:open("foo")
return $foo//whatever:p
Run Code Online (Sandbox Code Playgroud)