what's wrong with this updating function?

Wednesday, 11 December 2013 · 4 messages
E
easy11 Dec 2013 07:04 #
hi,all, I have write a restxq service, as following: ------------------------------- module namespace page = 'http://basex.orgs/examples/web-page'; declare %output:method("xhtml") %output:omit-xml-declaration("no") %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN") %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd") %updating %rest:path("/addehr") %rest:POST('{$ehr}') %rest:GET %rest:form-param("message","{$message}", "(no message)") %rest:header-param("User-Agent", "{$agent}") function page:hello-postman( $ehr, $message as xs:string, $agent as xs:string*) { let $path:=substring('5102108843434',1,3)||'/'||'test' let $test := 'ehr/v1/1382968159350/12001.xml' return for $x in doc($test)//header[id=12001] return db:output('ok,path='||$path), insert node ( 'text', <e>test</e> ) into $x };
-- but still say :undefined variavle $x. how to do ? is there a good way to do insert update operation on a file and return some customzied response? many Thanks. 此致 easy 莫愁前路无知己,天下谁人不识君。
WS
Wiemer, Sebastian11 Dec 2013 08:18 #
Quoted text · easy · 2 lines
Am 11.12.2013 um 07:04 schrieb easy <lin_xd at 126.com>: > hi,all,
hi 此致,
Quoted text · easy · 43 lines
> I have write a restxq service, as following: > > ------------------------------- > > module namespace page = 'http://basex.orgs/examples/web-page'; > > declare > > %output:method("xhtml") > > %output:omit-xml-declaration("no") > > %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN") > > %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd") > > %updating > > %rest:path("/addehr") > > %rest:POST('{$ehr}') > > %rest:GET > > %rest:form-param("message","{$message}", "(no message)") > > %rest:header-param("User-Agent", "{$agent}") > > function page:hello-postman( > > $ehr, > > $message as xs:string, > > $agent as xs:string*) > > { > > let $path:=substring('5102108843434',1,3)||'/'||'test' > > let $test := 'ehr/v1/1382968159350/12001.xml' > > return
$x is declared here
Quoted text · easy · 5 lines
> for $x in doc($test)//header[id=12001] > > return > > db:output('ok,path='||$path)
here ends the statement: db:output(…) is what you return, where $x is in scope
Quoted text · easy · 1 line
> , insert node ( 'text', <e>test</e> ) into $x
here $x is out of scope, because the comma separates the statements and this is simply an other statement. You can use parenthesis to put both statements in one sequence: ( db:output('ok,path='||$path) ,insert node ( 'text', <e>test</e> ) into $x ) You will then return a sequence with two items instead of returning „db:output(…)“ x-times and afterwards perform „insert node (…) into $x“ one time (where $x is out of scope) This might clarify things further:
for $i in 1 to 10 return $i,“I am the second statement and will executed only once, not ten times"
Quoted text · easy · 9 lines
> }; > > > > -- > > but still say :undefined variavle $x. > > how to do ? is there a good way to do insert update operation on a file and return some customzied response?
Yes: insert node ( 'text', <e>test</e> ) into $x ,db:output('ok,path='||$path) If $path should be out of scope, the same solution as mentioned above applies.
Quoted text · easy · 1 line
> many Thanks.
hope this helped, Sebastian
Quoted text · easy · 23 lines
> 此致 > > > > easy > > > > 莫愁前路无知己,天下谁人不识君。 > > > > > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
E
easy11 Dec 2013 11:55 #
Thanks. but how to custom update response type is application/xml ?
-- 此致 easy 莫愁前路无知己,天下谁人不识君。 在 2013-12-11 15:18:14,"Wiemer, Sebastian" <Sebastian.Wiemer at adesso.de> 写道:
Quoted text · Wiemer, Sebastian · 1 line
Am 11.12.2013 um 07:04 schrieb easy <lin_xd at 126.com>:
hi,all, hi 此致, I have write a restxq service, as following: ------------------------------- module namespace page = 'http://basex.orgs/examples/web-page'; declare %output:method("xhtml") %output:omit-xml-declaration("no") %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN") %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd") %updating %rest:path("/addehr") %rest:POST('{$ehr}') %rest:GET %rest:form-param("message","{$message}", "(no message)") %rest:header-param("User-Agent", "{$agent}") function page:hello-postman( $ehr, $message as xs:string, $agent as xs:string*) { let $path:=substring('5102108843434',1,3)||'/'||'test' let $test := 'ehr/v1/1382968159350/12001.xml' return $x is declared here for $x in doc($test)//header[id=12001] return db:output('ok,path='||$path) here ends the statement: db:output(…) is what you return, where $x is in scope , insert node ( 'text', <e>test</e> ) into $x here $x is out of scope, because the comma separates the statements and this is simply an other statement. You can use parenthesis to put both statements in one sequence: ( db:output('ok,path='||$path) ,insert node ( 'text', <e>test</e> ) into $x ) You will then return a sequence with two items instead of returning „db:output(…)“ x-times and afterwards perform „insert node (…) into $x“ one time (where $x is out of scope) This might clarify things further: for $i in 1 to 10 return $i,“I am the second statement and will executed only once, not ten times" }; -- but still say :undefined variavle $x. how to do ? is there a good way to do insert update operation on a file and return some customzied response? Yes: insert node ( 'text', <e>test</e> ) into $x ,db:output('ok,path='||$path) If $path should be out of scope, the same solution as mentioned above applies. many Thanks. hope this helped, Sebastian 此致 easy 莫愁前路无知己,天下谁人不识君。 _______________________________________________ BaseX-Talk mailing list BaseX-Talk at mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
AG
Arve Gengelbachin reply to easy, 11 Dec 2013, 07:0411 Dec 2013 12:25 #
Hi easy, try this:
let $path:=substring('5102108843434',1,3)||'/'||'test'
let $test := 'ehr/v1/1382968159350/12001.xml'
for $x in  doc($test)//header[id=12001]
return (
	db:output('ok,path='||$path),
	insert node (  'text', <e>test</e> ) into $x
)
This puts the insert statement into the scope of the defined $x. cheers Arve
Quoted text · easy · 44 lines
On 11 Dec 2013, at 07:04, easy <lin_xd at 126.com> wrote: > hi,all, > I have write a restxq service, as following: > ------------------------------- > module namespace page = 'http://basex.orgs/examples/web-page'; > declare > %output:method("xhtml") > %output:omit-xml-declaration("no") > %output:doctype-public("-//W3C//DTD XHTML 1.0 Transitional//EN") > %output:doctype-system("http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd") > %updating > %rest:path("/addehr") > %rest:POST('{$ehr}') > %rest:GET > %rest:form-param("message","{$message}", "(no message)") > %rest:header-param("User-Agent", "{$agent}") > function page:hello-postman( > $ehr, > $message as xs:string, > $agent as xs:string*) > { > let $path:=substring('5102108843434',1,3)||'/'||'test' > let $test := 'ehr/v1/1382968159350/12001.xml' > return > for $x in doc($test)//header[id=12001] > return > db:output('ok,path='||$path), insert node ( 'text', <e>test</e> ) into $x > }; > > -- > but still say :undefined variavle $x. > how to do ? is there a good way to do insert update operation on a file and return some customzied response? > many Thanks. > 此致 > > easy > > 莫愁前路无知己,天下谁人不识君。 > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk

⚡Generated with XQuery