restxq with html form get, syntax to declare variable as argument

Wednesday, 15 January 2014 · 21 messages · last reply 16 Jan 2014
E
e-letter15 Jan 2014 12:01 #
The 'restxq.xqm' was edited as below: (:~ : This module contains some basic examples for RESTXQ annotations : @author BaseX Team :) module namespace page = 'http://basex.org/modules/web-page'; (:~ : This function generates the welcome page. : @return HTML page :) declare %rest:path("{$x}") %output:method("xhtml") %output:omit-xml-declaration("no") %output:doctype-public("-//W3C//DTD XHTML Basic 1.1//EN") %output:doctype-system("http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd") function page:start($x) as element(Q{http://www.w3.org/1999/xhtml}html) { <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>BaseX HTTP Services</title> <link rel="stylesheet" type="text/css" href="static/style.css"/> </head> <body> <h3>Example 2</h3> <p>The next example presents how form data is processed via RESTXQ and the POST method:</p> <form method='get' name='databasequeryform'
Quoted text · 1 line
>
				<p>
					<select
						name='booktitle'
Quoted text · 1 line
>
						<option>
							Everyday Italian
						</option>
						<option>
							Harry Potter
						</option>
					</select>
					<input
						type="submit"
						value='send'
						/>
				</p>
			</form>
	</body>
</html>
};
declare
%rest:GET
%rest:path("xmldatabasefile.xml/bookstore/book")
%rest:form-param("booktitle","{$x}")
%rest:produces("text/html")
%output:method("xhtml")
function page:bookstore() as element(bookstore) {
	<bookstore>
		{
			let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday
Italian')]/parent::*
				return $x
		}
	</bookstore>
	};
The server response: HTTP ERROR 400 Problem accessing /. Reason: Stopped at /path/to/webapp/restxq.xqm, 58/10: [BASX0003] Variable $x is not specified as argument. Powered by Jetty:// What is my mistake for the declaration: ... function page:bookstore() as element(bookstore) { ...
CG
Christian Grün15 Jan 2014 13:22 #
Quoted text · e-letter · 3 lines
> What is my mistake for the declaration: > > function page:bookstore() as element(bookstore) {
The error message may serve as inspiration:
Quoted text · e-letter · 1 line
> [BASX0003] Variable $x is not specified as argument.
The examples in our documentation may be helpful, too: http://docs.basex.org/wiki/RESTXQ#Query_Parameters
E
e-letter15 Jan 2014 15:43 #
Quoted text · Christian Grün · 9 lines
On 15/01/2014, Christian Grün <christian.gruen at gmail.com> wrote: >> What is my mistake for the declaration: >> >> function page:bookstore() as element(bookstore) { > > The error message may serve as inspiration: > >> [BASX0003] Variable $x is not specified as argument. >
I don't understand.
Quoted text · Christian Grün · 4 lines
> The examples in our documentation may be helpful, too: > > http://docs.basex.org/wiki/RESTXQ#Query_Parameters >
The query component is the xquery function below, correct? : let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday Italian')]/parent::* The result of this query is selection of all the sibling elements for this book title element. In the documentation example:
declare
  %rest:path("/params")
  %rest:query-param("id", "{$id}")
  %rest:query-param("add", "{$add}", 42, 43, 44)
  function page:params($value as xs:string?, $answer as xs:integer+)
{
  <result id="{ $id }" sum="{ sum($add) }"/>
};

It is not seen where '$value' and '$answer' originate. In my example,
I have only one variable, '$x'.
CG
Christian Grün15 Jan 2014 15:45 #
This should help: function page:bookstore($x)
Quoted text · e-letter · 33 lines
>> The error message may serve as inspiration: >> >>> [BASX0003] Variable $x is not specified as argument. >> > > I don't understand. > >> The examples in our documentation may be helpful, too: >> >> http://docs.basex.org/wiki/RESTXQ#Query_Parameters >> > > The query component is the xquery function below, correct? : > > let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday > Italian')]/parent::* > > The result of this query is selection of all the sibling elements for > this book title element. > > In the documentation example: > > declare > %rest:path("/params") > %rest:query-param("id", "{$id}") > %rest:query-param("add", "{$add}", 42, 43, 44) > function page:params($value as xs:string?, $answer as xs:integer+) > { > <result id="{ $id }" sum="{ sum($add) }"/> > }; > > It is not seen where '$value' and '$answer' originate. In my example, > I have only one variable, '$x'.
E
e-letter15 Jan 2014 21:23 #
Quoted text · Christian Grün · 5 lines
On 15/01/2014, Christian Grün <christian.gruen at gmail.com> wrote: > This should help: > > function page:bookstore($x) >
I tried:
...
function page:bookstore($x) as element(bookstore) {
	<bookstore>
		{
			let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday
Italian')]/parent::*
				return $x
		}
	</bookstore>
	};
The result: HTTP ERROR 404 Problem accessing /. Reason: No function found that matches the request. Powered by Jetty:// Then I tried: ... function page:bookstore($x) {... which produces the same error result shown above. Then tried:
...
function page:bookstore($x)
	<bookstore>
		{
			let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday
Italian')]/parent::*
				return $x
		}
	</bookstore>
The result: HTTP ERROR 400 Problem accessing /. Reason: Stopped at /path/to/webapp/restxq.xqm, 59/2: [XPST0003] Expecting '{', found '<'. Powered by Jetty:// What next must I try, please?
CG
Christian Grün15 Jan 2014 21:52 #
Quoted text · e-letter · 2 lines
> Problem accessing /. Reason: > No function found that matches the request.
404 indicates that your XQuery code is correct, but that no mapping for your URL is found. What are the values for.. - your URL? - your %rest:path argument? - your RESTXQ url-pattern in web.xml? Usually, the easiest way is to start off with the given examples (in the BaseX zip/exe distribution or the ones shown in the Wiki) and modify them to your needs.
Quoted text · e-letter · 31 lines
> > Powered by Jetty:// > > Then I tried: > > ... > function page:bookstore($x) {... > > which produces the same error result shown above. Then tried: > > ... > function page:bookstore($x) > <bookstore> > { > let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday > Italian')]/parent::* > return $x > } > </bookstore> > > The result: > > HTTP ERROR 400 > > Problem accessing /. Reason: > Stopped at /path/to/webapp/restxq.xqm, 59/2: > [XPST0003] Expecting '{', found '<'. > > Powered by Jetty:// > > What next must I try, please?
DK
Dirk Kirstenin reply to e-letter, 15 Jan 2014, 21:2315 Jan 2014 21:53 #
Hi, based on your recent questions I would really recommend that you try to understand RESTXQ in more detail. Apart from our documentation at https://docs.basex.org/wiki/RESTXQ (which Chrisdtian already pointed out), there was also a Talk given by Arve and Sabine named "How to develop RESTXQ-based web applications with BaseX", you can find the slides and the example code at https://files.basex.org/publications/xmlprague2013/. All the details are given in the Spec at http://exquery.github.io/exquery/exquery-restxq-specification/restxq-1.0-specification.html You are using an annotation %rest:path("{$x}") This means, your URL can be basically be any atomic type (see http://exquery.github.io/exquery/exquery-restxq-specification/restxq-1.0-specification.html) and this value will be bound to the variable $x. This is also the reason why you have to declare $x as argument of the function. Within your function you never actually use this value, so probably you don't really intend to use a template in your path, so you might simply want to remove this. Of course, this is mostly guessing as we don't know what you actually want to do. Cheers, Dirk
Quoted text · Christian Grün · 58 lines
On 15/01/14 21:23, e-letter wrote: > On 15/01/2014, Christian Grün <christian.gruen at gmail.com> wrote: >> This should help: >> >> function page:bookstore($x) >> > > I tried: > > ... > function page:bookstore($x) as element(bookstore) { > <bookstore> > { > let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday > Italian')]/parent::* > return $x > } > </bookstore> > }; > > The result: > > HTTP ERROR 404 > > Problem accessing /. Reason: > No function found that matches the request. > > Powered by Jetty:// > > Then I tried: > > ... > function page:bookstore($x) {... > > which produces the same error result shown above. Then tried: > > ... > function page:bookstore($x) > <bookstore> > { > let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday > Italian')]/parent::* > return $x > } > </bookstore> > > The result: > > HTTP ERROR 400 > > Problem accessing /. Reason: > Stopped at /path/to/webapp/restxq.xqm, 59/2: > [XPST0003] Expecting '{', found '<'. > > Powered by Jetty:// > > What next must I try, please? >
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
E
e-letter15 Jan 2014 22:47 #
Quoted text · Dirk Kirsten · 11 lines
On 15/01/2014, Dirk Kirsten <dk at basex.org> wrote: > Hi, > > based on your recent questions I would really recommend that you try to > understand RESTXQ in more detail. Apart from our documentation at > https://docs.basex.org/wiki/RESTXQ (which Chrisdtian already pointed > out), there was also a Talk given by Arve and Sabine named "How to > develop RESTXQ-based web applications with BaseX", you can find the > slides and the example code at > https://files.basex.org/publications/xmlprague2013/. >
This presentation does seem connected to my set up. For example it states that webapp must be run using maven via port 9876, but I am using 'basexhttp' which I access via a web browser and url 'localhost:8984'.
Quoted text · Dirk Kirsten · 15 lines
> All the details are given in the Spec at > http://exquery.github.io/exquery/exquery-restxq-specification/restxq-1.0-specification.html > > You are using an annotation > %rest:path("{$x}") > > This means, your URL can be basically be any atomic type (see > http://exquery.github.io/exquery/exquery-restxq-specification/restxq-1.0-specification.html) > and this value will be bound to the variable $x. This is also the reason > why you have to declare $x as argument of the function. > Within your function you never actually use this value, so probably you > don't really intend to use a template in your path, so you might simply > want to remove this. Of course, this is mostly guessing as we don't know > what you actually want to do. >
The objective is to use basex to query an xml database using and html select form and return the result in a web page (see: http://www.mail-archive.com/basex-talk at mailman.uni-konstanz.de/msg03469.html). When the list item 'every day italian' is selected, a new web page should be created which displays the 'title', 'author', 'year', 'price' elements of the parent element 'book'.
E
e-letterin reply to Christian Grün, 15 Jan 2014, 21:5215 Jan 2014 22:56 #
Quoted text · Christian Grün · 8 lines
On 15/01/2014, Christian Grün <christian.gruen at gmail.com> wrote: >> Problem accessing /. Reason: >> No function found that matches the request. > > 404 indicates that your XQuery code is correct, but that no mapping > for your URL is found. What are the values for.. > > - your URL?
The xml database file is stored in '/path/to/webapp' and the url is stated in the xqm file as: ... %rest:path("xmldatabasefile.xml/bookstore/book") ...
Quoted text · Christian Grün · 1 line
> - your %rest:path argument?
As above, is correct?
Quoted text · Christian Grün · 1 line
> - your RESTXQ url-pattern in web.xml?
/path/to/webapp/WEB-INF/web.xml:
line77    <url-pattern>/*</url-pattern>
97    <url-pattern>/rest/*</url-pattern>
117    <url-pattern>/webdav/*</url-pattern>
130    <url-pattern>/static/*</url-pattern>
Quoted text · Christian Grün · 5 lines
> > Usually, the easiest way is to start off with the given examples (in > the BaseX zip/exe distribution or the ones shown in the Wiki) and > modify them to your needs. >
I've tried using the wiki page suggested, without any success in understanding (!)
CG
Christian Grün15 Jan 2014 23:36 #
Quoted text · e-letter · 4 lines
>> - your URL? > > The xml database file is stored in '/path/to/webapp' and the url is > stated in the xqm file as:
But which URL causes the 404 error?
Quoted text · e-letter · 3 lines
> %rest:path("xmldatabasefile.xml/bookstore/book") > /path/to/webapp/WEB-INF/web.xml: > line77 <url-pattern>/*</url-pattern>
So your URL should probably look sth like.. http://localhost:8984/xmldatabasefile.xml/bookstore/book
Quoted text · e-letter · 2 lines
> I've tried using the wiki page suggested, without any success in > understanding (!)
What are the problems? Christian
E
e-letter16 Jan 2014 00:46 #
Quoted text · Christian Grün · 6 lines
On 15/01/2014, Christian Grün <christian.gruen at gmail.com> wrote: > > So your URL should probably look sth like.. > > http://localhost:8984/xmldatabasefile.xml/bookstore/book >
I had to enclosedthe url in quotation marks: ... declare %rest:GET %rest:path("http://localhost:8984/xmldatabasefile.xml/bookstore/book") %rest:form-param("booktitle","{$x}") %rest:produces("text/html") %output:method("xhtml") function page:bookstore($x) { <bookstore> { let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday Italian')]/parent::* return $x } </bookstore> }; The result: HTTP ERROR 404 Problem accessing /. Reason: No function found that matches the request. Powered by Jetty:// With the quotation marks removed around the url, the server result: HTTP ERROR 400 Problem accessing /. Reason: Stopped at /path/to/webapp/restxq.xqm, 54/12: [XPST0003] Literal expected after annotation. Powered by Jetty://
Quoted text · Christian Grün · 4 lines
>> I've tried using the wiki page suggested, without any success in >> understanding (!) > > What are the problems?
It is incomplete, to my usage scenario. For example, the wiki page does not show an example with the localhost as part of the url.
DK
Dirk Kirsten16 Jan 2014 01:33 #
Hello,
Quoted text · e-letter · 2 lines
> It is incomplete, to my usage scenario. For example, the wiki page > does not show an example with the localhost as part of the url.
It is not incomplete, such a construct simply does not exist and it can not be executed this way (hence, we do not have an example for that...). It also does not make much sense: Imagine, you would write something like "ftp://....." as your path - RestXQ can not, of course, magically change the protocol. This is done on a different layer, i.e. the server. Let suppose you want your final URL (which you use to access the page in the browser) to be http://localhost:8984/xmldatabasefile.xml/bookstore/book This consists of two parts: The first one is the server url mapping, where all RESTXQ URIs are bound to. In this case, this would be http://localhost:8984/ The second part is the path given as RESTXQ annotation, in this case xmldatabasefile.xml/bookstore/book So you should instead use the annotation %rest:path("xmldatabasefile.xml/bookstore/book") to access your ressource at the URL given above, assuming you are binding RESTXQ execution to the root of your server, which is running on localhost:8984 (this is the default). Cheers, Dirk
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
E
e-letter16 Jan 2014 11:11 #
Quoted text · Dirk Kirsten · 8 lines
On 16/01/2014, Dirk Kirsten <dk at basex.org> wrote: > > It is not incomplete, such a construct simply does not exist and it can > not be executed this way (hence, we do not have an example for that...). > It also does not make much sense: Imagine, you would write something > like "ftp://....." as your path - RestXQ can not, of course, magically > change the protocol. This is done on a different layer, i.e. the server. >
If such a construct does not exist, does this mean I cannot test with a local installation?
Quoted text · Dirk Kirsten · 18 lines
> Let suppose you want your final URL (which you use to access the page in > the browser) to be > http://localhost:8984/xmldatabasefile.xml/bookstore/book > > This consists of two parts: The first one is the server url mapping, > where all RESTXQ URIs are bound to. In this case, this would be > http://localhost:8984/ > > The second part is the path given as RESTXQ annotation, in this case > xmldatabasefile.xml/bookstore/book > > So you should instead use the annotation > %rest:path("xmldatabasefile.xml/bookstore/book") > > to access your ressource at the URL given above, assuming you are > binding RESTXQ execution to the root of your server, which is running on > localhost:8984 (this is the default). >
I changed the restxq.xqm: (:~ : This module contains some basic examples for RESTXQ annotations : @author BaseX Team :) module namespace page = 'http://basex.org/modules/web-page'; (:~ : This function generates the welcome page. : @return HTML page :) declare %rest:path("{$x}") %output:method("xhtml") %output:omit-xml-declaration("no") %output:doctype-public("-//W3C//DTD XHTML Basic 1.1//EN") %output:doctype-system("http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd") function page:start($x) as element(Q{http://www.w3.org/1999/xhtml}html) { <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>BaseX HTTP Services</title> <link rel="stylesheet" type="text/css" href="static/style.css"/> </head> <body> <h3>Example 2</h3> <p>The next example presents how form data is processed via RESTXQ and the POST method:</p> <form method='get' name='databasequeryform'
Quoted text · Dirk Kirsten · 1 line
>
				<p>
					<select
						name='booktitle'
Quoted text · Dirk Kirsten · 1 line
>
						<option>
							Everyday Italian
						</option>
						<option>
							Harry Potter
						</option>
					</select>
					<input
						type="submit"
						value='send'
						/>
				</p>
			</form>
	</body>
</html>
};
declare
%rest:GET
%rest:path("xmldatabasefile.xml/bookstore/book")
%rest:form-param("booktitle","{$x}")
%rest:produces("text/html")
%output:method("xhtml")
function page:bookstore($x) {
	<bookstore>
		{
			let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday
Italian')]/parent::*
				return $x
		}
	</bookstore>
	};
I started the server from the command terminal (pwd=./bin) ./basexhttp Then I open a new web browser (opera) window and enter the url http://localhost:8984 The response is: HTTP ERROR 404 Problem accessing /. Reason: No function found that matches the request. Powered by Jetty:// I close this web browser window. Then I stop the server entering the following command in a separate terminal window: ./basehttp stop The command terminal (where the server was started) response: $ ./basexhttp BaseX 7.7.2 [Server] Server was started (port: 1984) HTTP Server was started (port: 8984) Server was stopped (port: 1984) HTTP Server was stopped (port: 8984) The restxq file is edited: ... %rest:path(http://localhost:8984/xmldatabasefile.xml/bookstore/book) ... The web server is re-started as described previously and the server response: HTTP ERROR 400 Problem accessing /. Reason: Stopped at /path/to/webapp/restxq.xqm, 54/12: [XPST0003] Literal expected after annotation. Powered by Jetty:// Where is my mistake please? The xml file:
<?xml version="1.0" encoding="utf-8"?>
<!-- Edited by XMLSpy®, taken from http://www.w3schools.com
<?xml-stylesheet type='text/xsl" href="xstylesheetexample.xslt" ?>-->
<bookstore>
	<book
		category="COOKING">
		<title
			lang="en"
Quoted text · Dirk Kirsten · 1 line
>
			Everyday Italian
		</title>
		<author>Giada De Laurentiis</author>
		<year>2005</year>
		<price>30.00</price>
	</book>
	<book
		category="CHILDREN"
Quoted text · Dirk Kirsten · 1 line
>
		<title
			lang="en"
Quoted text · Dirk Kirsten · 1 line
>
			Harry Potter
		</title>
		<author>J K. Rowling</author>
		<year>2005</year>
		<price>29.99</price>
	</book>
	<book
		category="WEB"
Quoted text · Dirk Kirsten · 1 line
>
		<title
			lang="en"
Quoted text · Dirk Kirsten · 1 line
>
			XQuery Kick Start
		</title>
		<author>James McGovern</author>
		<author>Per Bothner</author>
		<author>Kurt Cagle</author>
		<author>James Linn</author>
		<author>Vaidyanathan Nagarajan</author>
		<year>2003</year>
		<price>49.99</price>
	</book>
	<book
		category="WEB"
Quoted text · Dirk Kirsten · 1 line
>
		<title
			lang="en"
Quoted text · Dirk Kirsten · 1 line
>
			Learning XML
		</title>
		<author>Erik T. Ray</author>
		<year>2003</year>
		<price>39.95</price>
	</book>
</bookstore>
DK
Dirk Kirsten16 Jan 2014 11:34 #
Once again, the error message "No function found that matches the request." is quite helpful. There simply is no RESTXQ path, that matches your URL. You have two paths defined: %rest:path("{$x}") %rest:path("xmldatabasefile.xml/bookstore/book") Given your configuration, you can access these functions using the following URLs: - For %rest:path("{$x}") it can be anything like http://localhost:8984/test or http://localhost:8984/test2 and test (or test2) will be bound to the variable $x - For %rest:path("xmldatabasefile.xml/bookstore/book") it will be http://localhost:8984/xmldatabasefile.xml/bookstore/book
Quoted text · Dirk Kirsten · 209 lines
On 16/01/14 11:11, e-letter wrote: > On 16/01/2014, Dirk Kirsten <dk at basex.org> wrote: >> >> It is not incomplete, such a construct simply does not exist and it can >> not be executed this way (hence, we do not have an example for that...). >> It also does not make much sense: Imagine, you would write something >> like "ftp://....." as your path - RestXQ can not, of course, magically >> change the protocol. This is done on a different layer, i.e. the server. >> > > If such a construct does not exist, does this mean I cannot test with > a local installation? > >> Let suppose you want your final URL (which you use to access the page in >> the browser) to be >> http://localhost:8984/xmldatabasefile.xml/bookstore/book >> >> This consists of two parts: The first one is the server url mapping, >> where all RESTXQ URIs are bound to. In this case, this would be >> http://localhost:8984/ >> >> The second part is the path given as RESTXQ annotation, in this case >> xmldatabasefile.xml/bookstore/book >> >> So you should instead use the annotation >> %rest:path("xmldatabasefile.xml/bookstore/book") >> >> to access your ressource at the URL given above, assuming you are >> binding RESTXQ execution to the root of your server, which is running on >> localhost:8984 (this is the default). >> > > I changed the restxq.xqm: > > (:~ > : This module contains some basic examples for RESTXQ annotations > : @author BaseX Team > :) > module namespace page = 'http://basex.org/modules/web-page'; > > (:~ > : This function generates the welcome page. > : @return HTML page > :) > declare > %rest:path("{$x}") > %output:method("xhtml") > %output:omit-xml-declaration("no") > %output:doctype-public("-//W3C//DTD XHTML Basic 1.1//EN") > %output:doctype-system("http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd") > function page:start($x) > as element(Q{http://www.w3.org/1999/xhtml}html) > { > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > <title>BaseX HTTP Services</title> > <link rel="stylesheet" type="text/css" href="static/style.css"/> > </head> > <body> > <h3>Example 2</h3> > <p>The next example presents how form data is processed via RESTXQ > and the POST method:</p> > <form > method='get' > name='databasequeryform' > > > <p> > <select > name='booktitle' > > > <option> > Everyday Italian > </option> > <option> > Harry Potter > </option> > </select> > <input > type="submit" > value='send' > /> > </p> > </form> > </body> > </html> > }; > declare > %rest:GET > %rest:path("xmldatabasefile.xml/bookstore/book") > %rest:form-param("booktitle","{$x}") > %rest:produces("text/html") > %output:method("xhtml") > function page:bookstore($x) { > <bookstore> > { > let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday > Italian')]/parent::* > return $x > } > </bookstore> > }; > > I started the server from the command terminal (pwd=./bin) > ./basexhttp > > Then I open a new web browser (opera) window and enter the url > > http://localhost:8984 > > The response is: > > HTTP ERROR 404 > > Problem accessing /. Reason: > No function found that matches the request. > > Powered by Jetty:// > > I close this web browser window. Then I stop the server entering the > following command in a separate terminal window: > > ./basehttp stop > > The command terminal (where the server was started) response: > > $ ./basexhttp > BaseX 7.7.2 [Server] > Server was started (port: 1984) > HTTP Server was started (port: 8984) > Server was stopped (port: 1984) > HTTP Server was stopped (port: 8984) > > The restxq file is edited: > > ... > %rest:path(http://localhost:8984/xmldatabasefile.xml/bookstore/book) > ... > > The web server is re-started as described previously and the server response: > > HTTP ERROR 400 > > Problem accessing /. Reason: > Stopped at /path/to/webapp/restxq.xqm, 54/12: > [XPST0003] Literal expected after annotation. > > Powered by Jetty:// > > Where is my mistake please? > > The xml file: > > <?xml version="1.0" encoding="utf-8"?> > <!-- Edited by XMLSpy®, taken from http://www.w3schools.com > <?xml-stylesheet type='text/xsl" href="xstylesheetexample.xslt" ?>--> > <bookstore> > <book > category="COOKING"> > <title > lang="en" > > > Everyday Italian > </title> > <author>Giada De Laurentiis</author> > <year>2005</year> > <price>30.00</price> > </book> > <book > category="CHILDREN" > > > <title > lang="en" > > > Harry Potter > </title> > <author>J K. Rowling</author> > <year>2005</year> > <price>29.99</price> > </book> > <book > category="WEB" > > > <title > lang="en" > > > XQuery Kick Start > </title> > <author>James McGovern</author> > <author>Per Bothner</author> > <author>Kurt Cagle</author> > <author>James Linn</author> > <author>Vaidyanathan Nagarajan</author> > <year>2003</year> > <price>49.99</price> > </book> > <book > category="WEB" > > > <title > lang="en" > > > Learning XML > </title> > <author>Erik T. Ray</author> > <year>2003</year> > <price>39.95</price> > </book> > </bookstore> >
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
E
e-letter16 Jan 2014 11:46 #
Quoted text · Dirk Kirsten · 10 lines
On 16/01/2014, Dirk Kirsten <dk at basex.org> wrote: > > Given your configuration, you can access these functions using the > following URLs: > - For %rest:path("{$x}") it can be anything like > http://localhost:8984/test or http://localhost:8984/test2 and test (or > test2) will be bound to the variable $x > - For %rest:path("xmldatabasefile.xml/bookstore/book") it will be > http://localhost:8984/xmldatabasefile.xml/bookstore/book >
The urls were enclosed in quotation marks: ... %rest:path("http://localhost:8984/test") ... %rest:path("http://localhost:8984/xmldatabasefile.xml/bookstore/book") ... The server response: HTTP ERROR 400 Problem accessing /. Reason: Stopped at /path/to/webapp/restxq.xqm, 17/10: [BASX0003] Variable $x is not assigned by the annotations. Powered by Jetty:// What are these annotations please?
DK
Dirk Kirsten16 Jan 2014 11:49 #
No, you don't want to change your %rest:path() annotation. You _never_ put anything like http://localhost into your %rest:path() annotation. The URLs I have given are the URLs you have to enter in your browser to access this functions.
Quoted text · Dirk Kirsten · 32 lines
On 16/01/14 11:46, e-letter wrote: > On 16/01/2014, Dirk Kirsten <dk at basex.org> wrote: >> >> Given your configuration, you can access these functions using the >> following URLs: >> - For %rest:path("{$x}") it can be anything like >> http://localhost:8984/test or http://localhost:8984/test2 and test (or >> test2) will be bound to the variable $x >> - For %rest:path("xmldatabasefile.xml/bookstore/book") it will be >> http://localhost:8984/xmldatabasefile.xml/bookstore/book >> > > The urls were enclosed in quotation marks: > > ... > %rest:path("http://localhost:8984/test") > ... > %rest:path("http://localhost:8984/xmldatabasefile.xml/bookstore/book") > ... > > The server response: > > HTTP ERROR 400 > > Problem accessing /. Reason: > Stopped at /path/to/webapp/restxq.xqm, 17/10: > [BASX0003] Variable $x is not assigned by the annotations. > > Powered by Jetty:// > > What are these annotations please? >
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
E
e-letter16 Jan 2014 12:03 #
Quoted text · Dirk Kirsten · 6 lines
On 16/01/2014, Dirk Kirsten <dk at basex.org> wrote: > No, you don't want to change your %rest:path() annotation. You _never_ > put anything like http://localhost into your %rest:path() annotation. > The URLs I have given are the URLs you have to enter in your browser to > access this functions. >
The result of the url 'http://localhost:8984/test' in the web browser is a web page with the html form. Finally, I have made a millimetre of progress! :) The result of 'http://localhost:8984/xmldatabasefile.xml/bookstore/book' is: HTTP ERROR 404 Problem accessing /xmldatabasefile.xml/bookstore/book. Reason: No function found that matches the request. Powered by Jetty://
DK
Dirk Kirsten16 Jan 2014 12:07 #
Quoted text · Dirk Kirsten · 11 lines
On 16/01/14 12:03, e-letter wrote: > On 16/01/2014, Dirk Kirsten <dk at basex.org> wrote: >> No, you don't want to change your %rest:path() annotation. You _never_ >> put anything like http://localhost into your %rest:path() annotation. >> The URLs I have given are the URLs you have to enter in your browser to >> access this functions. >> > > The result of the url 'http://localhost:8984/test' in the web browser > is a web page with the html form. Finally, I have made a millimetre of > progress! :)
We are very happy to hear that!
Quoted text · e-letter · 9 lines
> > The result of 'http://localhost:8984/xmldatabasefile.xml/bookstore/book' is: > > HTTP ERROR 404 > > Problem accessing /xmldatabasefile.xml/bookstore/book. Reason: > No function found that matches the request. > > Powered by Jetty://
Could you please send the whole function + annotations once again? However, it should work if your path annotation is: %rest:path("xmldatabasefile.xml/bookstore/book")
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
E
e-letter16 Jan 2014 12:21 #
Quoted text · e-letter · 27 lines
On 16/01/2014, Dirk Kirsten <dk at basex.org> wrote: > On 16/01/14 12:03, e-letter wrote: >> On 16/01/2014, Dirk Kirsten <dk at basex.org> wrote: >>> No, you don't want to change your %rest:path() annotation. You _never_ >>> put anything like http://localhost into your %rest:path() annotation. >>> The URLs I have given are the URLs you have to enter in your browser to >>> access this functions. >>> >> >> The result of the url 'http://localhost:8984/test' in the web browser >> is a web page with the html form. Finally, I have made a millimetre of >> progress! :) > > We are very happy to hear that! > >> >> The result of 'http://localhost:8984/xmldatabasefile.xml/bookstore/book' >> is: >> >> HTTP ERROR 404 >> >> Problem accessing /xmldatabasefile.xml/bookstore/book. Reason: >> No function found that matches the request. >> >> Powered by Jetty:// > > Could you please send the whole function + annotations once again?
Not necessary, I found my mistake, which to use the http domain.
Quoted text · Dirk Kirsten · 4 lines
> However, it should work if your path annotation is: > > %rest:path("xmldatabasefile.xml/bookstore/book") >
With this applied, and the url 'http://localhost:8984/xmldatabasefile.xml/bookstore/book' loaded into the web browser, I finally have a desirable result! Giada De Laurentiis 2005 30.00 However, it is noticed that the web browser window title has changed to: 'Everyday Italian - Opera' What has caused this behaviour? Also for the web browser url 'http://localhost:8984/test', the html form is visible, but submitting the 'get' request does not return the result of the query.
DK
Dirk Kirsten16 Jan 2014 12:55 #
Quoted text · e-letter · 16 lines
>> However, it should work if your path annotation is: >> >> %rest:path("xmldatabasefile.xml/bookstore/book") >> > > With this applied, and the url > 'http://localhost:8984/xmldatabasefile.xml/bookstore/book' loaded into > the web browser, I finally have a desirable result! > > Giada De Laurentiis 2005 30.00 > > However, it is noticed that the web browser window title has changed to: > > 'Everyday Italian - Opera' > > What has caused this behaviour?
We can't control this, this is done by your browser. Quite likely it handles the <title /> node the same it would normally handle the <title /> node within an HTML head element.
Quoted text · e-letter · 4 lines
> > Also for the web browser url 'http://localhost:8984/test', the html > form is visible, but submitting the 'get' request does not return the > result of the query.
Your <form /> element needs an action attribute, otherwise it sends it to the some URL. So it should be <form method='get' name='databasequeryform' action="xmldatabasefile.xml/bookstore/book"
Quoted text · e-letter · 1 line
>
Please be also aware that this has nothing to do with BaseX, XQuery or XPath, but is standard HTML. So your question might be more appropriate at other places, e.g. StackOverflow. There are also great debugging tools integrated into modern browsers (Firebug for Firefox, Developer toolbar for Chrome, ...) where you can see all your requests and you could immediately spot that your request is going to the wrong address. Cheers, Dirk
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
E
e-letter16 Jan 2014 13:44 #
Quoted text · Dirk Kirsten · 6 lines
On 16/01/2014, Dirk Kirsten <dk at basex.org> wrote: > > We can't control this, this is done by your browser. Quite likely it > handles the <title /> node the same it would normally handle the <title > /> node within an HTML head element. >
OK, thanks; will test in another browser.

⚡Generated with XQuery