Thanks for the hints. I can finally agree it’s a bug ;) I have added a GitHub issue for it [1]. The problem only occurs with "database nodes" (which are the ones created via "fn:doc", "fetch:xml", or by applying transformations via "copy $c := ..." or "... update {}".
This looks to me like a generall weakness of the EXPath spec in general: A namespace declaration will always be valid for all descendant nodes of an element. As it doesn’t make sense to keep the http namespace when supplying bodies via http:send-request, we are explicitly removing the namespace from the body node before sending it out. As there is no such functionality in XQuery like “removing namespaces”, this operation is not well-defined, and it’s probably the reason for this bug.
I hope I’ll find time to fix this soon.
Cheers, Christian
[1] https://github.com/BaseXdb/basex/issues/1353
On Fri, Sep 16, 2016 at 4:06 PM, Christian Grün christian.gruen@gmail.com wrote:
Hm. I can’t reproduce it..
- I stored your module as 'example.xqm' in the WEBPATH directory
- I started basexhttp
- I created an empty 'exampledb' database in the GUI and closed it again
- I ran your script in the GUI (after rewriting fetch:xml(...) with <example/>)
- I ran db:open('exambledb')
Did I do something wrong?
By the way, if possible, remove everything from your examples that required manual post-processing. Could you please check the following code and tell me how the returned XML looks like?
_ example.xqm ___________
module namespace example = 'http://localhost/example'; declare %rest:path("/example") %rest:POST("{$body}") function example:post($body) { $body };
_ test.xqm ___________
http:send-request( <http:request href="http://localhost:8984/example" method='POST'> <http:body media-type='text/xml'> <example/> </http:body> </http:request> )[2]
On my system, I get "<example/>".
On Thu, Sep 15, 2016 at 2:34 PM, chrisis chrisisanon@gmail.com wrote:
Hi Christian
Sorry, chopped that out of the real thing in a bit of a hurry and made a bit of a mess of it. Here's something slightly closer to a SSCE.
Module under WEBPATH
xquery version "3.1" encoding "utf-8"; module namespace example = 'http://localhost/example'; declare %rest:path("/example/post/{$fname}") %rest:POST("{$body}") %updating function example:post($fname, $body as document-node()) {db:replace('exampledb', '/post/'||$fname, $body) };
Script run in BaseX GUI
let $file := 'C:\temp\xq\example.xml' let $fname := 'example.xml' let $targetrestxqproc := 'http://localhost:8984/example/post/' let $body := fetch:xml($file, map { 'chop': true() }) return http:send-request(<http:request href="{$targetrestxqproc||$fname}" method='POST'> <http:body media-type='text/xml'>{$body}</http:body> </http:request>)
Result in exampledb is
<example xmlns:http="http://expath.org/ns/http-client"/>