How to unencode shielded XML using xQuery

I have a variable in xQuery of type xs: string with the value of the encoded HTML snippet (twitter twitter content). It looks like this:

Headlines-Today & # 8226; Sources of AP: & amp; l; b & gt; Obama & l; / b & gt; to choose for Justice goes: News - Recreation Of World - & lt; a href = " http://shar.es/mqMAG">http://shar.es/mqMAG</a> ;

When I try to write this in an HTML block, I need the string to be non-isolated so that the HTML fragment is interpreted by the browser. Instead, the line is written out as is, and the browser passes it as simple text (so you see <a href = "blah ....). Here's how I write this line:

{$ record / atom: Contents / text ()}

How can I remove escaped characters, rather tha & lt;

I tried to do this with a replacement, but it always replaces & lt; with & lt;

fn: replace ($ s, "& lt;", "<")

+7
xml xquery marklogic
source share
3 answers

In MarkLogic, you can use the following query:

let $d := '<a>&lt;c&gt;asdf&lt;/c&gt;</a>' return xdmp:unquote ($d) 
+3
source share

in eXist, use util: parse ():

 util:parse(concat("<top>","&lt;c&gt;asdf&lt;/c&gt;",</top>")‌​) 
+3
source share

Depends on which XQuery processor you are using ... The easiest way is to use a processor that has an extension that handles this for you. For example, with Saxon and the following XML :

 <a>&lt;c&gt;asdf&lt;/c&gt;</a> 

You can write 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> 

Result:

 <a> <c>asdf</c> </a> 

I think most (?) XQuery processors will have an extension to do this for you. Hope this helps.

+2
source share

All Articles