0

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:

a

and

b


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
    Your collection is wrong: `collection("/db/tmp")` – jbrehr Nov 21 '20 at 09:00
  • ah, but still same error about `no root element`. – Nicholas Saunders Nov 21 '20 at 09:07
  • 1
    What happens if you remove everything and just run this query: `xquery version "3.0"; collection("/db/tmp")` ? And what happens if you run this: `xquery version "3.0"; doc("/db/tmp/notes.xml")` ? (i.e. leave out the FLOWR) – jbrehr Nov 21 '20 at 09:12
  • How do I "run" the simple `xquery` you have? that sounds like a good idea. see also: https://sourceforge.net/p/exist/mailman/message/34308441/ where I agree: the documentation isn't clear to me as to how to do this. – Nicholas Saunders Nov 21 '20 at 09:17
  • 1
    In eXide you click the button 'new' to create a query. Paste the query above into the query window. Click the button 'eval'. Results show in the bottom window. – jbrehr Nov 21 '20 at 11:00
  • 1
    btw eXide is an eXist-db specific development interface: you can execute all your queries there for testing, and you can manage the database collections and documents (delete, create, upload) through the eXide menu -> file -> manage. I recommend you use only eXide before experimenting in any way with eXist REST services. Create your XML document in eXide so that eXide can validate its structure. From there, progress to writing a query and executing it in eXide. This will make it easy for you to trap errors early - because at the moment it's impossible to diagnose your exact issues. – jbrehr Nov 21 '20 at 11:07

1 Answers1

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.

westbaystars
  • 151
  • 1
  • 4
  • XML Parsing Error: junk after document element Location: http://localhost:8080/exist/rest/db/scripts/notes.xq Line Number 7, Column 1: ^ – Nicholas Saunders Nov 21 '20 at 09:30
  • 1
    In eXide you can manage all collections and files in the db using the "manage" window (eXide menu -> file -> manage). – jbrehr Nov 21 '20 at 10:45
  • 1
    The error `XML Parsing Error: junk after document element` is because you have an XML document that is badly formed. – jbrehr Nov 21 '20 at 10:50