views:

61

answers:

1

We are using SQL Server 2005 and are trying to store an XML Type in the database. The XML type has an element that needs to contain the content in CDATA, yet once inserted, the field seems to be stripping the CDATA and storing the element without it...

Has anybody experienced or even resolved this in the past?

Handy example:

create table t (x xml)

insert into t values  ('<test>kjhghk</test>')
insert into t  values ('<test><![CDATA[kjhghk]]></test>')
select * from t

drop table t

results:

<test>kjhghk</test>
<test>kjhghk</test>
A: 

Unfortunately, this is standard behavior where the CDATA section is stripped and its content entitized. You could use the cdata directive of FOR XML EXPLICIT to add the content to a CDATA section when retrieving, but depending on the complexity of your XML this may be combersome. Also, see this post.

Garett
Bummer... what I expected - we are using hibernate to interface with JQL so no luck on the FOR XML syntax - I converted the field to NTEXT - we don't need to query the XML in he DB anyhow...
akaphenom