eXist 中的 FLWOR 查询给出:XML 解析错误:未找到根元素 [英] FLWOR query in eXist gives: XML Parsing Error: no root element found
问题描述
我希望将最简单的 FLWOR
从 BaseX
调整为 eXist
,如下所示.
I'm looking to adapt the simplest possible FLWOR
possible from BaseX
to eXist
as below.
eXist
中的错误:
XML Parsing Error: no root element found
Location: http://localhost:8080/exist/rest/db/scripts/notes.xq
Line Number 1, Column 1:
查询:
xquery version "3.0";
for $note in collection("/db/temp/notes")
return $note
集合:
<notes>
<note>
foo
</note>
<note>
bar
</note>
<note>
baz
</note>
</notes>
来自BaseX
:
nicholas@mordor:~/basex$
nicholas@mordor:~/basex$ cat notes.xq
xquery version "3.1";
for $note in db:open("notes")
return $note
nicholas@mordor:~/basex$
nicholas@mordor:~/basex$ basex notes.xq
[warning] /usr/bin/basex: Unable to locate /usr/share/java/tagsoup.jar in /usr/share/java
[warning] /usr/bin/basex: Unable to locate /usr/share/java/xml-resolver.jar in /usr/share/java
[warning] /usr/bin/basex: Unable to locate /usr/share/java/jing.jar in /usr/share/java
<notes>
<note>foo</note>
<note>bar</note>
<note>baz</note>
</notes>nicholas@mordor:~/basex$
nicholas@mordor:~/basex$
不确定如何将其调整为上述 eXist
.
not sure how to adapt that to eXist
as above.
次要问题是这是 3.0
并且 eXist
使用 3.1
,否则我希望它是可移植的.那么,一定是出现了一些语法或配置错误吗?
Minor point being that this is 3.0
and eXist
is using 3.1
, otherwise I'd expect it to be portable. So, must be making some syntax or configuration error?
不确定如何使用控制台";在 eXist
中所以来自 eXide
:
Not sure how to use a "console" in eXist
so from eXide
:
和
这个查询:
xquery version "3.0";
for $notes in collection('/db/temp')
return $notes
返回一个空白页.数据在文件"中.
returns a blank page. The data is in a "file" named notes.xml
in /db/tmp
as above.
我添加了一个 xml 声明:
I added an xml declaration of:
<?xml version="1.0" encoding="UTF-8" ?>
同样,到数据xml
文档.
推荐答案
看起来您在/db/tmp 中有两个 XML 文件(不是/db/temp).我假设 note.xml 是单个
文档,notes.xml 是
包含三个
元素的文档.
It looks like you have two XML files in /db/tmp (not /db/temp). I assume that note.xml is a single <note>...</note>
document and notes.xml is the <notes>...</notes>
document containing three <note>...</note>
elements.
您看到的错误是因为您没有从集合中请求任何元素.也就是说,一旦有了集合,就需要使用 XPath 语句指定该集合中的元素.
The error you are seeing is because you are not requesting any elements from the collection. That is, once you have a collection, you need to specify the elements within that collection with an XPath statement.
请试试这个:
xquery version "3.0";
for $note in collection('/db/tmp')//note
return $note
//注意"将获取集合中每个文档根元素下的所有
元素.这应该返回 notes.xml 中的三个 <note>...</note>
标签加上 <note>...</note>
note.xml 中的文档.
The "//note" will get all <note>...</note>
elements below each document's root element in the collection. This should return the three <note>...</note>
tags in the notes.xml plus the <note>...</note>
document in note.xml.
如果您将查询的 XPath 部分更改为/notes/note"那么您将只能从 notes.xml 文档中获得三个.这是因为 note.xml 文档的根目录中没有
元素.
If you change the XPath portion of the query to "/notes/note" then you'll only get the three from the notes.xml document. That is because the note.xml document does not have a <notes>...</notes>
element in its root.
您是对的,在这种情况下,XQuery 3.0 或 3.1 版并不重要.在这个简单的查询中没有 3.1 函数.
You are correct in that XQuery version 3.0 or 3.1 doesn't matter in this case. There are no 3.1 functions in this simple of a query.
这篇关于eXist 中的 FLWOR 查询给出:XML 解析错误:未找到根元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!