Hi Robert, 

Yeah, that’s not necessarily obvious, but the type of the document you post is „document-node()“ not element() — so simply change the function & argument types to document-node() and you will be fine.


Usually the the in-browser debugging > Network view helps with identifying such „low-level“ errors, yet I tend to use the command-line more often since I discovered httpie[1]

echo "<xml/>"|http POST http://localhost:8984/test Content-Type:text/xml
HTTP/1.1 400 Bad Request
Stopped at /Users/michael/tmp/ml/webapp/foo.xqm, 5/10:
[XPTY0004] Cannot convert document-node() to element(): document-node {''}.

Hope this helps & best from Konstanz 

Michael


[1] https://httpie.org



Am 06.05.2019 um 14:09 schrieb Robert Kirkpatrick <robert@eridan.net>:

Hello,

I am trying to implement an XForm for posting data via:

<xf:submission resource="http://localhost:8984/test" method="post" 
  serialization="application/xml" replace="all" />

It should invoke the following query (in webapp):

module namespace page = 'http://basex.org/examples/web-page';
declare
  %rest:path("/test")
  %rest:POST("{$data}")
function page:hello ( $data as element() ) 
as element() { $data };

But I get this instead:
<image.png>
TIA for any help,
Robert.