﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Programming / XML  / Nested XML/CDATA ... / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 13:38:53 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Nested XML/CDATA ...</title><link>http://www.sqlservercentral.com/Forums/Topic1414614-21-1.aspx</link><description>Hi,Personally, if I was to approach this from the SQL server side of things, I would do something like the following. It isn't pretty, but it works and I hope that someone could post a better solution here :-D[code="sql"]DECLARE @xml XMLSET @xml = '&amp;lt;DOWNLOADED-SCRIPT SCRIPTID="blah" OBJECTTYPE="IS"&amp;gt;    &amp;lt;SCRIPT-MAIN&amp;gt;      &amp;lt;![CDATA[		&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;          &amp;lt;Script ScriptId="blah" StartNode="600001" LastModifiedBy="xxxxxx" BeginDate=""&amp;gt;            &amp;lt;Node NodeId="600001" TemplateId="Dialogue" X="595" Y="1215" Column="-1" Row="-1" NodeType="template"&amp;gt;              &amp;lt;Resource URI="Package_Type" Name="Survey"/&amp;gt;              &amp;lt;NodeDescription Language="en" Text="Package Type?"/&amp;gt;              &amp;lt;NodeDescription Language="cs" Text=""/&amp;gt;            &amp;lt;/Node&amp;gt;            &amp;lt;Node ChapterId="1" NodeId="600002" TemplateId="Dialogue" X="5982" Y="2407" Column="-1" Row="-1" NodeType="template"&amp;gt;              &amp;lt;Resource URI="Fault_Type?" Name="Survey"/&amp;gt;              &amp;lt;NodeDescription Language="en" Text="Fault Type?"/&amp;gt;			&amp;lt;/Node&amp;gt;		&amp;lt;/Script&amp;gt;		]]&amp;gt;	&amp;lt;/SCRIPT-MAIN&amp;gt;&amp;lt;/DOWNLOADED-SCRIPT&amp;gt;'--Extract xml in cdata sectionDECLARE @InnerXmltext VARCHAR(MAX)SELECT @InnerXmltext = LTRIM(@xml.value('(//SCRIPT-MAIN/text())[1]', 'varchar(max)'))--Get declaration at start of stringSET @InnerXmltext = SUBSTRING(@InnerXmltext, CHARINDEX('&amp;lt;', @InnerXmltext), LEN(@InnerXmltext))--cast string to xmlDECLARE @InnerXml XMLSET @InnerXml = CAST(@InnerXmltext AS XML)SELECT @InnerXml[/code]The idea is that the query first extracts the contents of the cdata section into a varchar(max) variable. Then the code trims of the padding at the start of the @InnerXmltext so that the xml declaration is at the start of the text. This should make the contents of @InnerXmltext valid and able to cast to xml so that you can start to use the xml functions against it.</description><pubDate>Fri, 01 Feb 2013 06:51:31 GMT</pubDate><dc:creator>arthurolcot</dc:creator></item><item><title>Nested XML/CDATA ...</title><link>http://www.sqlservercentral.com/Forums/Topic1414614-21-1.aspx</link><description>I've been kindly given some XML, and asked to return relevant values from within.Now I have only done simple xml before, and this one has me beat.It seams to have a second xml document nested within one of the nodes wrapped by a CDATA tag.I have a sneaking feeling that whoever write the application that produces this xml, should have provided us with the facility to read it ! .. but regardless, this is the situation as of today.Could anyone point me in the right direction to being able to decipher this and strip/display the node values?Many Thanks[code]&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&amp;lt;DOWNLOADED-SCRIPT SCRIPTID="blah" OBJECTTYPE="IS"&amp;gt;    &amp;lt;SCRIPT-MAIN&amp;gt;      &amp;lt;![CDATA[        &amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;          &amp;lt;Script ScriptId="blah" StartNode="600001" LastModifiedBy="xxxxxx" BeginDate=.....&amp;lt;truncated for post&amp;gt;            &amp;lt;Node NodeId="600001" TemplateId="Dialogue" X="595" Y="1215" Column="-1" Row="-1" NodeType="template"&amp;gt;              &amp;lt;Resource URI="Package_Type" Name="Survey"/&amp;gt;              &amp;lt;NodeDescription Language="en" Text="Package Type?"/&amp;gt;              &amp;lt;NodeDescription Language="cs" Text=""/&amp;gt;            &amp;lt;/Node&amp;gt;            &amp;lt;Node ChapterId="1" NodeId="600002" TemplateId="Dialogue" X="5982" Y="2407" Column="-1" Row="-1" NodeType="template"&amp;gt;              &amp;lt;Resource URI="Fault_Type?" Name="Survey"/&amp;gt;              &amp;lt;NodeDescription Language="en" Text="Fault Type?"/&amp;gt;... etc etc[/code]</description><pubDate>Fri, 01 Feb 2013 06:00:17 GMT</pubDate><dc:creator>Sim-473257</dc:creator></item></channel></rss>