简体   繁体   中英

RestXQ [XPTY0004] Cannot convert empty-sequence() to document-node()

I have a RestXQ method:

declare
    %rest:path("/doSomething")
    %rest:POST
    %rest:form-param("name","{$name}")
    function page:doSomething($name as document-node())
    {
        (: Code... :)
    };

I tried to send a POST request to this method via XForms. As response on the client I get [XPTY0004] Cannot convert empty-sequence() to document-node(): (). I tried to remove document-node() but then the parameter $name is just empty.

The request parameter looks like this:

<data xmlns=""><name>Test</name></data>

Any solutions?

The problem is that %rest:form-param("name","{$name}") is for key-value pairs, but your method indicates that you want $name as document-node() . Those two things together don't make sense.

Instead of the form-param you likely want the body of the POST request, for that you would use the following:

declare
  %rest:path("/doSomething")
  %rest:POST("{$body}")
function page:doSomething($body as document-node())
{
    (: Code... :)
};

See http://www.adamretter.org.uk/papers/restful-xquery_january-2012.xhtml#media-example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM