how to create a xml document on the fly with xquery? -
I use XML in XML like "aaa = 1 & amp; bbb = 2" in xml
& lt; Request & gt; & Lt; Aaa & gt; 1 & lt; / Aaa & gt; & Lt; Bbb & gt; 2 & lt; / Bbb & gt; & Lt; / Request & gt; I have tried the following code, but failed!
Exquisite version "1.0" encoding "GBK"; (:: Prague Type = "xs: anyType"): announcement of names xf = "http://tempuri.org/BNetAP/Xquery/query2xml/"; Function declare xf: query2xml (XS: string as $ queryStr) as element (*) {& lt; Query-parameters & gt; {$ C in fn: tokenize ($ queryStr, "&") Give $ myname as xs: string: = "{fn: substring-before ($ c," = "}" return element {fn : Quenam ("", $ myname)} {"{fn: substring-after ($ c," = "}}"}} & lt; / Query-params & gt; }; The error message is:
line 15, column 6: "{http://www.w3.org/2004/07/xpath-QN Name ": unknown work (or number of arguments (2) is wrong) BNetAP / Xquery query2xml.xq line 15 1241431186406 397 I do not know why" QName "is an" unknown function "? !
You should use constructor xs: QName, not fn: QName.
The body of your manufactured element also looks suspicious:
"{fn: substring-after ($ c," = =)} In fact, the content of the element will be just "false" text compared to between / pre> string {{fn: substring-after ($ c, "and string")} ".
Similarly, the $ myname variable is actually set to false and therefore a type of check error will increase on run time.
Your functions should probably be as follows:
declared function xf: query2xml (as the XS: string as $ queryStr) element (*) {& lt; Que ry-parameter & gt; {$ C in fn: tokenize ($ queryStr, "&") $ myname: = fn: substring-before ($ c, "=") return element {xs: QName ("", $ myname)} { Fn: substring-after ($ c, "=")}} & lt; / Query-params & gt; };
A mathematical element creator can also accept a string for its name, so your return expression is only
return element {$ myname} {Fn : After substring- ($ c, "="}}
Comments
Post a Comment