Bar*_*man 6 html xml sql sql-server-2005 sql-server-2008
当我编写查询以生成xml标记时,我想在我的sql查询中保留html标记.例如:
select '<p> this is a code</p>' as code
from table name
for xml path (''), type
Run Code Online (Sandbox Code Playgroud)
输出:
<code><p> this is a code </p> <code>
Run Code Online (Sandbox Code Playgroud)
它应该输出什么:
<code><p> this is a code </p><code>
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?谢谢!
如果使用xhtml,我相信转换为Xml会做:
select convert(xml, '<p> this is a code</p>') as code
from table name
for xml path (''), type
Run Code Online (Sandbox Code Playgroud)
编辑:如果列是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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7597 次 |
| 最近记录: |