如何使用xQuery对转义的XML进行解编码 [英] How to unencode escaped XML with xQuery

查看:75
本文介绍了如何使用xQuery对转义的XML进行解编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在xQuery中有一个xs:string类型的变量,其值带有一个已编码的HTML代码段(twitter推文的内容)的值.看起来像这样:

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:

今天的头条新闻&#8226; AP来源: < b& gt;奥巴马&/b& gt;选择 司法职位撤回:新闻-休息 世界-& lt; a href =& quot; http://shar.es/mqMAG&http://shar.es/mqMAG</a&gt ;

Headlines-Today &#8226; AP sources: &lt;b&gt;Obama&lt;/b&gt; pick for Justice post withdraws : News - Rest Of World - &lt;a href=&quot;http://shar.es/mqMAG&quot;&gt;http://shar.es/mqMAG&lt;/a&gt;

当我尝试在HTML块中将其写出时,我需要将字符串转义,以便浏览器可以解释HTML代码段.取而代之的是,字符串按原样被写出,浏览器将其呈现为纯文本形式(因此您会看到< a href ="blah ....).这是我写出此字符串的方式:

When I try to write this out in an HTML block, I need the string to be unescaped so that the HTML snippet will be interpreted by the browser. Instead the string is getting written out as is and the browser is rendering it as just text (so you see <a href="blah.... ). Here's how I'm writing out this string:

{$ entry/atom:content/text()}

{$entry/atom:content/text()}

我该如何对转义字符进行未编码,使其写为< ;?宁可?

How can I have the escaped characters unencoded so it writes < rather tha &lt; ?

我尝试过这样的替换,但是它总是替换& lt;与& lt; !

I've tried to do a replacelike this but it always replaces the &lt; with &lt; !

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

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

推荐答案

在eXist中,使用util:parse():

in eXist, use util:parse():

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

这篇关于如何使用xQuery对转义的XML进行解编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆