gpt4 book ai didi

html - 使用sql查询xml时如何保留HTML标签?

转载 作者:太空狗 更新时间:2023-10-29 15:02:04 26 4
gpt4 key购买 nike

当我编写生成 xml 标记的查询时,我想在我的 sql 查询中保留 html 标记。例如:

select '<p> this is a code</p>' as code
from table name
for xml path (''), type

输出:

<code>&ltp&gt; this is a code &lt/p&gt; <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

关于html - 使用sql查询xml时如何保留HTML标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10875577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com