I am extracting XML from a table using FOR XML clause.
select
maincode as cod_deal
, catcode as cod_category
, catname as title_category
...
from myTable
for xml raw, elements
Some fields contains HTML tags (<span>s). The resulting XML display escaped tags:
<span>my field content</span>
instead of
<span>my field content</span>
How may I prevent tsql escapes tags?
EDITED.
Note. Wrapping the <![CDATA[...]]> tag around the <span> tag does not do the work. The ‘<‘ and ‘>’ characters of CDATA are escaped as well!!
I’m not entirely sure that is what you want. But…
Sample data:
The equivalent of your query against this table:
The result from this will be one row and one column that holds a XML document that looks like this:
This is the way it has to look if you want
<span>my field content 1</span>to be the value of elementcol.What you are asking for could be created like this:
And this will also return one row with one XML column like this:
Here you have
<span>my field content 1</span>as a child node toColnot as a value.If you have your XML escaped you will get the correct values back when you extract them from the XML. Something like this in TSQL but should be the same in other languages.
Result: