如何让 SQL 查询不转义查询中返回的 HTML 数据 [英] How to get SQL query to not escape HTML data returned in query

查看:36
本文介绍了如何让 SQL 查询不转义查询中返回的 HTML 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 SQL 查询....

I have the following SQL query....

select AanID as '@name', '<![CDATA[' + Answer + ']]>' from AuditAnswers for XML PATH('str'), ROOT('root')

效果很好,但答案"列有时可以包含 HTML 标记.查询会自动从生成的 XML 的答案"列中转义此 HTML.我不想要那个.我将在 CDATA 中包装这个结果列,因此不需要转义.

which works wonderfully but the column 'Answer' can sometimes have HTML markup in it. The query automatically escapes this HTML from the 'Answer' column in the generated XML. I don't want that. I will be wrapping this resulting column in CDATA so the escaping is not necessary.

我希望结果是这样...

I want the result to be this...

<str name="2"><![CDATA[<DIV><DIV Style="width:55%;float:left;">Indsfgsdfg]]></str>

而不是这个...

<str name="2">&lt;![CDATA[&lt;DIV&gt;&lt;DIV Style="width:55%;float:left;"&gt;In</str>

是否有函数或其他机制可以做到这一点?

Is there a function or other mechanism to do this?

推荐答案

您可以使用 for xml explicitcdata 指令:

You can use for xml explicit and the cdata directive:

select
   1 as tag,
   null as parent,
   AanID as [str!1!name],
   Answer as [str!1!!cdata]
from AuditAnswers
for xml explicit

这篇关于如何让 SQL 查询不转义查询中返回的 HTML 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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