I think what you're wrestling with is peculiar to the XQuery eval environment
(cq or qconsole), and won't be necessary for an external string from HTTP,
Java, etc.
There are quite a few quirks around XQuery and escaping. But note that this
works:
<p>hello & goodbye</p>,
xdmp:unquote(xdmp:quote(<p>hello & goodbye</p>))/p
=>
<p>hello & goodbye</p>
<p>hello & goodbye</p>
The output from xdmp:quote appears to be just '<p>hello & goodbye</p>' -
but when we write that same string in XQuery code, we need to escape the
ampersand again. This might show us the way:
xdmp:describe(xdmp:quote(<p>hello & goodbye</p>))
=>
"<p>hello &amp; goodbye</p>"
That tells you what the string needs to look like in cq or qconsole:
double-escaped. The XQuery string represents an escaped ampersand for itself,
and another level of escaping for XML.
xdmp:unquote('<p>hello &amp; goodbye</p>')
=>
<p>hello & goodbye</p>
But the HTTP request field or Java string would simply be '<p>hello &
goodbye</p>'. The double-escaping is only needed in string literals within
XQuery code.
-- Mike
On 5 Oct 2012, at 14:04 , David Scott Gurney wrote:
> I have a need to convert a string that has an ampersand into xml and I can't
> get it to work. I have tried encoding the ampersand, but none of them seem to
> work. The string is coming from a system external to MarkLogic and it can be
> changed (if that will help).
>
> xquery version "1.0-ml";
> declare namespace html = "http://www.w3.org/1999/xhtml";
>
> (:let $testString1 := "<root>foo & bar</root>":)
> let $testString2 := "<root>foo & bar</root>"
> let $testString3 := "<root>foo & bar</root>"
> let $testString4 := "<root>foo %26 bar</root>"
> let $testString5 := "<root>foo & bar</root>"
> let $testString6 := "<root>foo & bar</root>"
> let $testString7 := "<root>foo %26 bar</root>"
> return xdmp:unquote($testString5)
>
>
> Maybe there is another way to convert the string into xml?
>
> I'm using MarkLogic 5.0-3.3
>
> Thanks
> David
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general