FLWOR query in eXist gives: XML Parsing Error: no root element found

陌路散爱 提交于 2021-02-11 15:14:37

问题


I'm looking to adapt the simplest possible FLWOR possible from BaseX to eXist as below.

Error in eXist:

XML Parsing Error: no root element found
Location: http://localhost:8080/exist/rest/db/scripts/notes.xq
Line Number 1, Column 1:

Query:

xquery version "3.0";


for $note in collection("/db/temp/notes")


return $note

Collection:

<notes>


<note>
foo
</note>


<note>
bar
</note>


<note>
baz
</note>

</notes>

from 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$ 

not sure how to adapt that to eXist as above.

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?

Not sure how to use a "console" in eXist so from eXide:

and


this query:

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.

I added an xml declaration of:

<?xml version="1.0" encoding="UTF-8" ?>

as well, to the data xml document.


回答1:


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.

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.

Please try this:

xquery version "3.0";

for $note in collection('/db/tmp')//note
  return $note

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.

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.

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.



来源:https://stackoverflow.com/questions/64941000/flwor-query-in-exist-gives-xml-parsing-error-no-root-element-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!