I am trying to use the http interface to access a BaseX database.
The setup is as follows:
- installed the latest basex on my windows 10 system (version 10.7)
- created a user test with password test
- imported a simple xml:
` <?xml version="1.0" encoding="UTF-8"?>
<musicCollection>
<entry>
<Type>CD</Type>
<Name>Greatest Hits</Name>
<Artist>The Music Band</Artist>
<Year>1998</Year>
<Songs>
<Song>
<Name>Song 1</Name>
<Author>John Songwriter</Author>
<Length>4:30</Length>
</Song>
<Song>
<Name>Song 2</Name>
<Author>Lisa Lyricist</Author>
<Length>3:45</Length>
</Song>
<Song>
<Name>Song 3</Name>
<Author>Lisa Lyricist</Author>
<Length>1:45</Length>
</Song>
</Songs>
</entry>
.... more entries
</musicCollection>
`
- checked the setup with the CLI interface:
java -cp BaseX.jar org.basex.BaseXClient ... login in as test / test ...
at the prompt:
xquery for $e in doc('music')/musicCollection/entry where $e/Type = "LP" return <entry> {$e/Type} {$e/Name} {$e/Artist} </entry>
Result:
<entry><Type>LP</Type><Name>Rock Revolution</Name><Artist>The Rockers</Artist></entry>
<entry><Type>LP</Type><Name>Rock Revolution</Name><Artist>The Other Ones</Artist></entry>
Query "BaseX" executed in 6.44 ms.
- then I started the http subsystem with the included script on port 123:
"D:\Programs\BaseX\bin\basexhttp.bat" -h123
- in another command shell I used curl to access the database:
curl -u test:test -X POST -d "for $e in doc('music')/musicCollection/entry return <entry> {$e/Type} {$e/Name} {$e/Artist} </entry>" "http://localhost:123/rest"
and this:
curl -u test:test -X POST -d "for $e in /musicCollection/entry return <entry> {$e/Type} {$e/Name} {$e/Artist} </entry>" "http://localhost:123/rest/music"
` I got this error reply:
"" (Line 1): Content ist nicht zulässig in Prolog. (Line 1: content is illegal in prolog)
trying this:
curl -u test:test -X POST -d "<query>for $e in /musicCollection/entry return <entry> {$e/Type} {$e/Name} {$e/Artist} </entry></query>" "http://localhost:123/rest/music"
i got:
Stopped at D:/Programs/BaseX/webapp, 1/1:
[XPST0003] Empty query.
with this:
curl -u test:test -X POST -d "<query><text>for $e in /musicCollection/entry return <entry> {$e/Type} {$e/Name} {$e/Artist} </entry></text></query>" "http://localhost:123/rest/music"
i got this error:
Stopped at D:/Programs/BaseX/webapp, 1/41:
[XPST0003] Expecting return value.
What is the correct way to send this query?
Your last attempt to send the query with the POST method was pretty close: If your XQuery string includes angle brackets or XML entities, you’ll need to use CDATA to prevent your query characters from being interpreted as XML:
The CDATA section is not required if your query string is unambiguous: