7

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>

どうすればこれを解決できますか?ありがとう!

4

2 に答える 2

4

を使用している場合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
于 2012-06-04T02:25:13.387 に答える
2

以下のスニペットは私のために働きます

DECLARE @HTMLt  NVARCHAR(MAX)  ;

........

SET @HTMLt = REPLACE(REPLACE(REPLACE(@HTMLt,'&amp;','&' ) , '&lt;','<'),'&gt;','>');
于 2015-01-28T10:32:46.770 に答える