当我编写查询以生成 xml 标签时,我想在我的 sql 查询中保留 html 标签。例如:
select '<p> this is a code</p>' as code
from table name
for xml path (''), type
输出:
<code><p> this is a code </p> <code>
它应该输出什么:
<code><p> this is a code </p><code>
我该如何解决这个问题?谢谢!
当我编写查询以生成 xml 标签时,我想在我的 sql 查询中保留 html 标签。例如:
select '<p> this is a code</p>' as code
from table name
for xml path (''), type
输出:
<code><p> this is a code </p> <code>
它应该输出什么:
<code><p> this is a code </p><code>
我该如何解决这个问题?谢谢!
如果使用xhtml,我相信转换为Xml:
select convert(xml, '<p> this is a code</p>') as code
from table name
for xml path (''), type
编辑:如果列是ntext,则支持隐式转换Xml:
create table #t(html ntext)
insert into #t values(N'<p> this is a code</p>')
select convert(xml, html) as code
from #t
for xml path (''), type
drop table #t
下面的片段对我有用
DECLARE @HTMLt NVARCHAR(MAX) ;
........
SET @HTMLt = REPLACE(REPLACE(REPLACE(@HTMLt,'&','&' ) , '<','<'),'>','>');