I have a variable in xQuery of type xs:string with the value of an encoded HTML snippet (the content of a twitter tweet). It looks like this:
Headline
In MarkLogic you can use the below query:
let $d := '<a><c>asdf</c></a>'
return xdmp:unquote ($d)
in eXist, use util:parse():
util:parse(concat("<top>","<c>asdf</c>",</top>"))
Depends on which XQuery processor you are using... The easiest way is to be using a processor that has an extension that handles this for you. For instance, with Saxon and the following XML:
<a><c>asdf</c></a>
You can write an XQuery that uses the saxon:parse()
function to do what you want:
declare namespace saxon = "http://saxon.sf.net/";
<a>{
saxon:parse(doc('test.xml')/a)
}</a>
The result from that is:
<a>
<c>asdf</c>
</a>
I think most(?) XQuery processors will have an extension to do this for you. Hope that helps.