Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 XML CDATA

Author  Topic 

Alpicus
Starting Member

2 Posts

Posted - 2007-10-18 : 08:15:34
Hi,

When I execute the following script on SQL Server 2005 SP2 :

IF EXISTS (select * from sys.objects where name = 'TEXTEST2' and type_desc
= 'USER_TABLE')
BEGIN
DROP TABLE TEST.TEXTEST2
END
CREATE TABLE TEST.TEXTEST2
(
ARR XML
);
INSERT INTO TEST.TEXTEST2 (arr) VALUES ('<?xml version=''1.0''
encoding=''windows-1252''?><E0><E01 LT=''C''><![CDATA[L''échéancier &
env.ASP]]></E01><E02 LT=''C''><![CDATA["Tools" -->
"Terminkalender"]]></E02></E0>');

The result in the XML field (ARR) is :
<E0><E01 LT="C">L'échéancier & env.ASP</E01><E02 LT="C">"Tools" -->
"Terminkalender"</E02></E0>

Why the CDATA section is gone ?

Thanks in advance.


Phil Mermod
Pensia Ltd - R&D - CTO
www.pensia.com

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-18 : 08:29:36
they are removed in parse time. it's how it works
if you must preserve then use nvarchar(max)

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

Alpicus
Starting Member

2 Posts

Posted - 2007-10-18 : 08:40:06
Hi spirit1,

The objective of XML CDATA section is to keep the contents without any changes (Check the doc. : http://www.w3.org/TR/xml/#sec-cdata-sect)

Is there a way to have an XML field keeping the CDATA contents ?

TIA.

Phil Mermod
Pensia Ltd - R&D - CTO
www.pensia.com
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-18 : 09:00:09
i know that

declare @xml xml
set @xml = '<node><![CDATA[123 > 111]]></node>'
select @xml, datalength(@xml)


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page
   

- Advertisement -