Hi Christian,
I am getting this error with the below code
[FOUP0001] Document expected, <root>...</root> found.
Is this a problem with the way $new-doc is declared?
Thanks,
Colin
module namespace page = 'http://basex.org/modules/web-page';
declare %updating
%restxq:path("form/")
%restxq:POST
%restxq:form-param("content","{$form-input}", "'no message delivered'")
function page:add-doc($form-input as xs:string) {
let $new-doc:=
<root>
<tag>
<form-data>{ $form-input }</form-data>
</tag>
</root>
return (
db:add("test_db", $new-doc, "test.xml"),
db:output("database was updated.")
)
};
That's great - thanks!
I was looking here for list of all annotations:
http://docs.basex.org/wiki/RESTXQ
But now I see these - %public, %private, or %updating - on this page too:
http://docs.basex.org/wiki/XQuery_3.0#Annotations
Are there any other annotations recognized by basex?On Thu, Sep 6, 2012 at 3:37 PM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Colin,
sure; you need to mark your function as updating, and the db:output()
> Is it possible with restxq to add a document to a db? And if so, to also
> return an http response?
function will allow you to return data. Your updated example is shown
below.
Hope this helps,
Christian
___________________________________
module namespace page = 'http://basex.org/modules/web-page';
declare %updating
%restxq:path("form/")
%restxq:POST
%restxq:form-param("content","{$form-input}", "'no message delivered'")
function page:add-doc($form-input as xs:string) {return (
let $new-doc:=
<root>
<tag>
<form-data>{ $form-input }</form-data>
</tag>
</root>
db:add("test_db", $new-doc, "test.xml"),
db:output("database was updated.")
)
};