marklogic - XQuery concat not outputting document XML in expected way -
let $d := doc('foo.xml') return concat('let $d := 

', $d)
returns
let $d := bar
i need return:
let $d := <foo>bar</foo>
reading function signature fn:concat
, there no reason expect output xml. http://www.w3.org/tr/xpath-functions/#func-concat
fn:concat( $arg1 xs:anyatomictype?, $arg2 xs:anyatomictype?, ...) xs:string
that is, takes variable number of atomic items , returns string. if pass xml node, attempt atomize , return string result. if haven't run atomization yet, try string(doc($uri))
see happens.
ignoring that, looks you're trying build xquery expression using string manipulation - perhaps use xdmp:eval
? that's fine, don't pass in xml using xdmp:quote
. correctness, performance, , security reasons, right tool job external variable.
xdmp:eval(' declare variable $input external ; let $d := $input return xdmp:describe($d)', (xs:qname('input'), $d))
better yet, write string part separate xquery module , xdmp:invoke
same external variable parameters.
why way? correctness, efficiency , security. if habit of blindly evaluating strings, setting problems. passing node reference more efficient quoting large node. when quote xml string may end xquery-significant characters, such {
. have escape them (or switch using xdmp:unquote
, makes less efficient). escaping error-prone. in sql classic way handle bind variable, , xquery external variable. bind variables in sql, external variables handle escaping. makes injection attacks more difficult.
Comments
Post a Comment