On 02/01/2014, e-letter inpost@gmail.com wrote:
On 27/12/2013, e-letter inpost@gmail.com wrote:
declare %rest:path("/form") %rest:GET function page:post() { let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday Italian')]/parent::* return $x };
...
was changed to:
declare %rest:GET %rest:path(./xmldatabasefile.xml/bookstore/book) function book:bookstore() as element(bookstore) {
<bookstore> { let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday Italian')]/parent::* return $x } </bookstore> };
The server result:
HTTP ERROR 500
Problem accessing /. Reason: Unexpected error: Improper use? Potential bug? Your feedback is welcome: Contact: basex-talk@mailman.uni-konstanz.de Version: BaseX 7.7.2 Java: Sun Microsystems Inc., 1.6.0_24 OS: Linux, i386 Stack Trace: java.lang.NumberFormatException at java.math.BigDecimal.<init>(BigDecimal.java:516) at java.math.BigDecimal.<init>(BigDecimal.java:739) at org.basex.query.value.item.Dec.<init>(Dec.java:35) at org.basex.query.QueryParser.numericLiteral(QueryParser.java:2200) at org.basex.query.QueryParser.literal(QueryParser.java:2173) at org.basex.query.QueryParser.annotation(QueryParser.java:475) at org.basex.query.QueryParser.prolog2(QueryParser.java:423) at org.basex.query.QueryParser.parseLibrary(QueryParser.java:247) at org.basex.query.QueryContext.parseLibrary(QueryContext.java:194) at org.basex.http.restxq.RestXqModule.parseModule(RestXqModule.java:130) at org.basex.http.restxq.RestXqModule.parse(RestXqModule.java:51) at org.basex.http.restxq.RestXqModules.cache(RestXqModules.java:137) at org.basex.http.restxq.RestXqModules.cache(RestXqModules.java:104) at org.basex.http.restxq.RestXqModules.find(RestXqModules.java:59) at org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:27) at org.basex.http.BaseXServlet.service(BaseXServlet.java:58) at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:457) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:370) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:949) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1011) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:679)
Powered by Jetty://
This error was reported as a bug (https://github.com/BaseXdb/basex/issues/838) and the error identified as omission of quotation characters for the declaration function 'rest:path'. this correction was made and a new error was received:
HTTP ERROR 400
Problem accessing /. Reason: Stopped at /path/to/webapp/restxq.xqm, 58/10: [XPST0081] No namespace declared for 'book:bookstore'.
Powered by Jetty://
I have reviewed the specification 'xml namespaces' (http://www.w3.org/TR/2009/REC-xml-names-20091208/) but do not understand how and where to declare my namespace for the element book, because I do not have a urn, the database is a local xml file?
Hi,
as already said on Github, you have to declare your namespace, because your function is in the book namespace. You can do so with the statement
module namespace book = "YOUR-NAMESPACE"
at the beginning of your XQuery file (not your xml file!).
Take a look at our example at https://docs.basex.org/wiki/RESTXQ#Usage. Here you can see that for the function page:hello() the page namespace was declared beforehand using
module namespace page = 'http://basex.org/examples/web-page';
Cheers, Dirk
On 10/01/14 12:25, e-letter wrote:
On 02/01/2014, e-letter inpost@gmail.com wrote:
On 27/12/2013, e-letter inpost@gmail.com wrote:
declare %rest:path("/form") %rest:GET function page:post() { let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday Italian')]/parent::* return $x };
...
was changed to:
declare %rest:GET %rest:path(./xmldatabasefile.xml/bookstore/book) function book:bookstore() as element(bookstore) {
<bookstore> { let $x := fn:doc("xmldatabasefile.xml")/bookstore/book/title[contains(text(),'Everyday Italian')]/parent::* return $x } </bookstore> };
The server result:
HTTP ERROR 500
Problem accessing /. Reason: Unexpected error: Improper use? Potential bug? Your feedback is welcome: Contact: basex-talk@mailman.uni-konstanz.de Version: BaseX 7.7.2 Java: Sun Microsystems Inc., 1.6.0_24 OS: Linux, i386 Stack Trace: java.lang.NumberFormatException at java.math.BigDecimal.<init>(BigDecimal.java:516) at java.math.BigDecimal.<init>(BigDecimal.java:739) at org.basex.query.value.item.Dec.<init>(Dec.java:35) at org.basex.query.QueryParser.numericLiteral(QueryParser.java:2200) at org.basex.query.QueryParser.literal(QueryParser.java:2173) at org.basex.query.QueryParser.annotation(QueryParser.java:475) at org.basex.query.QueryParser.prolog2(QueryParser.java:423) at org.basex.query.QueryParser.parseLibrary(QueryParser.java:247) at org.basex.query.QueryContext.parseLibrary(QueryContext.java:194) at org.basex.http.restxq.RestXqModule.parseModule(RestXqModule.java:130) at org.basex.http.restxq.RestXqModule.parse(RestXqModule.java:51) at org.basex.http.restxq.RestXqModules.cache(RestXqModules.java:137) at org.basex.http.restxq.RestXqModules.cache(RestXqModules.java:104) at org.basex.http.restxq.RestXqModules.find(RestXqModules.java:59) at org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:27) at org.basex.http.BaseXServlet.service(BaseXServlet.java:58) at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:457) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:370) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:949) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1011) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:668) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:679)
Powered by Jetty://
This error was reported as a bug (https://github.com/BaseXdb/basex/issues/838) and the error identified as omission of quotation characters for the declaration function 'rest:path'. this correction was made and a new error was received:
HTTP ERROR 400
Problem accessing /. Reason: Stopped at /path/to/webapp/restxq.xqm, 58/10: [XPST0081] No namespace declared for 'book:bookstore'.
Powered by Jetty://
I have reviewed the specification 'xml namespaces' (http://www.w3.org/TR/2009/REC-xml-names-20091208/) but do not understand how and where to declare my namespace for the element book, because I do not have a urn, the database is a local xml file? _______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
On 10/01/2014, Dirk Kirsten dk@basex.org wrote:
Hi,
as already said on Github, you have to declare your namespace, because your function is in the book namespace. You can do so with the statement
module namespace book = "YOUR-NAMESPACE"
at the beginning of your XQuery file (not your xml file!).
Please excuse my stupidity for continuing to fail to understand.
A file with the suffix 'xqm' was edited from the original 'restxq.xqm' (which was removed from this directory) and placed in the directory 'webapp':
(:~ : 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("") %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() as element(Q{http://www.w3.org/1999/xhtml%7Dhtml) {...
Take a look at our example at https://docs.basex.org/wiki/RESTXQ#Usage. Here you can see that for the function page:hello() the page namespace was declared beforehand using
module namespace page = 'http://basex.org/examples/web-page';
I do not understand the url I must write for the element 'book', because I do not have a web site with a url that points to the element 'book'. I expect to add another line in my xqm file, something like:
... (:~ : This module contains some basic examples for RESTXQ annotations : @author BaseX Team :) module namespace page = 'http://basex.org/modules/web-page'; module namespace book = 'http://i.don%27t.know'; ...
Hi,
no problem at all, the mailinglist is actually for questions, so it is absolutely ok to ask questions, even if they are beginner questions. We are happy to welcome new XQuery developers in the community. XML namespaces is an important topic for XML related programming, so you might want to read in more detail about it.
I do not understand the url I must write for the element 'book', because I do not have a web site with a url that points to the element 'book'. I expect to add another line in my xqm file, something like:
... (:~ : This module contains some basic examples for RESTXQ annotations : @author BaseX Team :) module namespace page = 'http://basex.org/modules/web-page'; module namespace book = 'http://i.don%27t.know'; ...
You just want to have one module namespace statement. This statement determines the target namespace of the whole module, hence having multiple statements is invalid. See the spec for some more information: http://www.w3.org/TR/xquery/#id-module-declaration
Another very important point is the URI format of a namespace. Although it looks like an URL, it actually has nothing to do with it. It is actually just an identifier (in the same way a URL is an identifier for a certain webpage, this URIs server as identifier for a certain module). So you could have something like
module namespace book = 'http://your-company.org/my-project';
However, also a namespace like
module namespace book = 'ABC';
would be valid - but beware (!) that this is considered bad practice and you should not do that. Some pointer to a more detailed explanation: http://www.xml.com/pub/a/1999/01/namespaces.html
Cheers, Dirk
On 10/01/2014, Dirk Kirsten dk@basex.org wrote:
You just want to have one module namespace statement. This statement determines the target namespace of the whole module, hence having multiple statements is invalid. See the spec for some more information: http://www.w3.org/TR/xquery/#id-module-declaration
The specification states that every variable must be declared, but if the namespace 'http://basex.org/modules/web-page' does not include the element 'book' and any new namespace url that I declare does not include the basex web page modules, how can I declare only one valid namespace?
Hi,
I don't quite get what you are asking for. All functions within the module should belong to the same namespace. So i.e. you could simply put your bookstore() function into the page namespace (i.e. use "declare function page:bookstore()") or you could place all the functions bound to the page namespace to the book namespace.
Cheers, Dirk
On 10/01/14 13:47, e-letter wrote:
On 10/01/2014, Dirk Kirsten dk@basex.org wrote:
You just want to have one module namespace statement. This statement determines the target namespace of the whole module, hence having multiple statements is invalid. See the spec for some more information: http://www.w3.org/TR/xquery/#id-module-declaration
The specification states that every variable must be declared, but if the namespace 'http://basex.org/modules/web-page' does not include the element 'book' and any new namespace url that I declare does not include the basex web page modules, how can I declare only one valid namespace?
On 10/01/2014, Dirk Kirsten dk@basex.org wrote:
Hi,
I don't quite get what you are asking for. All functions within the module should belong to the same namespace. So i.e. you could simply put your bookstore() function into the page namespace (i.e. use "declare function page:bookstore()") or you could place all the functions bound to the page namespace to the book namespace.
Did not realise that it is possible add functions to an existing namespace; now understood, thanks.
On 10/01/2014, e-letter inpost@gmail.com wrote:
On 10/01/2014, Dirk Kirsten dk@basex.org wrote:
Hi,
I don't quite get what you are asking for. All functions within the module should belong to the same namespace. So i.e. you could simply put your bookstore() function into the page namespace (i.e. use "declare function page:bookstore()") or you could place all the functions bound to the page namespace to the book namespace.
changed the namespace function to:
... 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] Invalid path template: "$x".
Powered by Jetty://
basex-talk@mailman.uni-konstanz.de