RESTXQ and xsd validation strangeness
Friday, 13 May 2016 · 3 messages · last reply 22 May 2016
ML
Marco Lettere13 May 2016 09:57 #
Dear all,
this question triggers a dejavu in my head and I'm pretty sure this has been discussed some time ago so I'm not sure why it strikes back at us ... With the latest snapshot (but with 8.4.4 it's the same) downloaded just few minutes ago I start the basehttp server.
Then I add the foolowing RestXQ to the restxq.xqm file:
declare
%rest:path("/testxsd")
%rest:POST("{$body}")
%rest:consumes("application/xml")
function page:testxsd($body){
validate:xsd-info($body, "xsd.xsd")
};
I store the following dummy xsd as xsd.xsd in the webapp folder:<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="a"/>
</xs:schema>I invoke the restxq with:
curl -vd "<a/>" http://localhost:5000/testxsd -H
"Content-type:application/xml"
Getting back the following error:
Error 400 Stopped at /tmp/basex/webapp/restxq.xqm, 12/20:
[bxerr:BXVA0002] Validation could not be started: Resource
"/tmp/basex/POST.xml (No such file or directory)" not found.</title>This happens no matter what xml and what xsd is used. If I change $body with <a/> in the call to
validate:xsd-info everything works smoothly ... Any ideas?
Thanks,
Marco.MS
Michael Seiferle18 May 2016 12:38 #
Hi Marco,
this one is not too obvious, yet:
the type of $body is „document-node()“ not element, so what I think happens is the following:
Quoted text · Marco Lettere · 1 line
> validate:xsd-info($body…
receives a document-node() and somehow* BaseX passes a documents string representation to
validate:xsd-info(), which happens the be the documents base-uri(), hence: "tmp/basex/POST.xml could not be found".
I am not 100% sure my explanation is correct, yet you could solve your problem by passing the element child of that document-node to the validate function, as follows:declare
%rest:path("/testxsd")
%rest:POST("{$body}")
%rest:consumes("application/xml")
function page:testxsd($body as document-node()){
validate:xsd-report(
$body/element(),
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="a"/></xs:schema>)
};See this gist for my experiments:
https://gist.github.com/micheee/025ffed4fbb06bc4b4200ab959755e3b
Hope this helps
Michael
* -> somehow means: most probably specified by rules I do not know of ;-)
Quoted text · Marco Lettere · 38 lines
> Am 13.05.2016 um 09:57 schrieb Marco Lettere <m.lettere at gmail.com>: > > Dear all, > this question triggers a dejavu in my head and I'm pretty sure this has been discussed some time ago so I'm not sure why it strikes back at us ... > With the latest snapshot (but with 8.4.4 it's the same) downloaded just few minutes ago I start the basehttp server. > Then I add the foolowing RestXQ to the restxq.xqm file: > > declare > %rest:path("/testxsd") > %rest:POST("{$body}") > %rest:consumes("application/xml") > function page:testxsd($body){ > validate:xsd-info($body, "xsd.xsd") > }; > > I store the following dummy xsd as xsd.xsd in the webapp folder: > > <?xml version="1.0"?> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > > <xs:element name="a"/> > > </xs:schema> > > > I invoke the restxq with: > > curl -vd "<a/>" http://localhost:5000/testxsd -H "Content-type:application/xml" > > Getting back the following error: > > Error 400 Stopped at /tmp/basex/webapp/restxq.xqm, 12/20: > [bxerr:BXVA0002] Validation could not be started: Resource "/tmp/basex/POST.xml (No such file or directory)" not found.</title> > > This happens no matter what xml and what xsd is used. If I change $body with <a/> in the call to validate:xsd-info everything works smoothly ... > Any ideas? > Thanks, > Marco.
--
Michael Seiferle, BaseX GmbH, http://www.basexgmbh.de
|-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
|-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
| Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Fon: +49 7531 916 82 77
CG
Christian Grün22 May 2016 14:14 #
Hi Marco!
First, thanks to Michael for diving into this issue. It was a document URI, which was assigned to POST bodies, that caused this strange bug [1]. The problem has been fixed with the latest snapshot [2] (avl in a few min).
Christian
[1] https://github.com/BaseXdb/basex/commit/23092e76d6992a1d271e682370fd3e949b684eb0 [2] http://files.basex.org/releases/latest/
Quoted text · Michael Seiferle · 93 lines
On Wed, May 18, 2016 at 12:38 PM, Michael Seiferle <ms at basex.org> wrote: > Hi Marco, > > this one is not too obvious, yet: > > the type of $body is „document-node()“ not element, so what I think happens > is the following: > > validate:xsd-info($body… > > receives a document-node() and somehow* BaseX passes a documents string > representation to validate:xsd-info(), which happens the be the documents > base-uri(), hence: "`tmp/basex/POST.xml` could not be found". > > > I am not 100% sure my explanation is correct, yet you could solve your > problem by passing the element child of that document-node to the validate > function, as follows: > > declare > %rest:path("/testxsd") > %rest:POST("{$body}") > %rest:consumes("application/xml") > function page:testxsd($body as document-node()){ > validate:xsd-report( > $body/element(), > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element > name="a"/></xs:schema>) > }; > > See this gist for my experiments: > > https://gist.github.com/micheee/025ffed4fbb06bc4b4200ab959755e3b > > > Hope this helps > Michael > > * -> somehow means: most probably specified by rules I do not know of ;-) > > Am 13.05.2016 um 09:57 schrieb Marco Lettere <m.lettere at gmail.com>: > > Dear all, > this question triggers a dejavu in my head and I'm pretty sure this has been > discussed some time ago so I'm not sure why it strikes back at us ... > With the latest snapshot (but with 8.4.4 it's the same) downloaded just few > minutes ago I start the basehttp server. > Then I add the foolowing RestXQ to the restxq.xqm file: > > declare > %rest:path("/testxsd") > %rest:POST("{$body}") > %rest:consumes("application/xml") > function page:testxsd($body){ > validate:xsd-info($body, "xsd.xsd") > }; > > I store the following dummy xsd as xsd.xsd in the webapp folder: > > <?xml version="1.0"?> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> > > <xs:element name="a"/> > > </xs:schema> > > > I invoke the restxq with: > > curl -vd "<a/>" http://localhost:5000/testxsd -H > "Content-type:application/xml" > > Getting back the following error: > > Error 400 Stopped at /tmp/basex/webapp/restxq.xqm, 12/20: > [bxerr:BXVA0002] Validation could not be started: Resource > "/tmp/basex/POST.xml (No such file or directory)" not found.</title> > > This happens no matter what xml and what xsd is used. If I change $body with > <a/> in the call to validate:xsd-info everything works smoothly ... > Any ideas? > Thanks, > Marco. > > > > -- > Michael Seiferle, BaseX GmbH, http://www.basexgmbh.de > |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > `-- Fon: +49 7531 916 82 77 >
Written for BaseX 8.4. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery