469,288 Members | 2,357 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,288 developers. It's quick & easy.

CDATA string?

I have a string that is returned from a web service that is XML so the string
is enclosed in CDATA[![ . . . ]]. The string/data enclosed in the CDATA
section is real XML. If I try to LoadXml into an XmlDocument I get an
exception. Does anyone have suggestions on how I can strip the CDATA off of
the string so I can load the real XML into an XmlDocument?

Thank you.

Kevin
Nov 12 '05 #1
8 14132
Hello!
I have a string that is returned from a web service that is XML so the string
is enclosed in CDATA[![ . . . ]]. The string/data enclosed in the CDATA
section is real XML. If I try to LoadXml into an XmlDocument I get an
exception.


What type of exception do you get? Maybe it's invalid XML inside the
CDATA, best thing would be if you posted a sample of it...
--
Pascal Schmitt
Nov 12 '05 #2
One sample is:

<![CDATA[<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><TraceHeader
xmlns="http://tempuri.org/"><TransactionId>aeec01aa-08c4-46e7-bcd2-c7bfffe0205f</TransactionId><RequestId>219633cd-19c5-459a-8278-e6545d080e47</RequestId><TCode
/><RequestTraceOverride>false</RequestTraceOverride></TraceHeader></soap:Header><soap:Body><IVRRequest
xmlns="http://tempuri.org/"><IVRRequest
xmlns="http://dps.visa.com/PPC"><Request
xsi:type="ValidateActivationRequest"><SessionId>80 3593ee-11f6-4750-a5dd-764ff793d199</SessionId><DigitCode
/><PhoneNumberZip /><CVV2 /><CardExpDate>0406</CardExpDate><LastFourSSN
/><LastFourPhone>4567</LastFourPhone><ZipCode>53005</ZipCode></Request><CorrelationID>7caaee26-fecf-4374-a183-bc4d858477cb</CorrelationID></IVRRequest></IVRRequest></soap:Body></soap:Envelope> ]]>

Thanks in advance for your ideas.

Kevin

"Pascal Schmitt" wrote:
Hello!
I have a string that is returned from a web service that is XML so the string
is enclosed in CDATA[![ . . . ]]. The string/data enclosed in the CDATA
section is real XML. If I try to LoadXml into an XmlDocument I get an
exception.


What type of exception do you get? Maybe it's invalid XML inside the
CDATA, best thing would be if you posted a sample of it...
--
Pascal Schmitt

Nov 12 '05 #3
Kevin Burton wrote:
I have a string that is returned from a web service that is XML so the
string
is enclosed in CDATA[![ . . . ]]. The string/data enclosed in the CDATA
section is real XML. If I try to LoadXml into an XmlDocument I get an
exception. Does anyone have suggestions on how I can strip the CDATA off
of the string so I can load the real XML into an XmlDocument?


See http://xml.silmaril.ie/authors/cdata/

///Peter

Nov 12 '05 #4
Unfortunately I don't have a choice on the string the string that I am
presented wit is wrapped in <![CDATA[.....]]. I just have to deal with it.

"Peter Flynn" wrote:
Kevin Burton wrote:
I have a string that is returned from a web service that is XML so the
string
is enclosed in CDATA[![ . . . ]]. The string/data enclosed in the CDATA
section is real XML. If I try to LoadXml into an XmlDocument I get an
exception. Does anyone have suggestions on how I can strip the CDATA off
of the string so I can load the real XML into an XmlDocument?


See http://xml.silmaril.ie/authors/cdata/

///Peter

Nov 12 '05 #5
Kevin Burton wrote:
I have a string that is returned from a web service that is XML so the string
is enclosed in CDATA[![ . . . ]]. The string/data enclosed in the CDATA
section is real XML. If I try to LoadXml into an XmlDocument I get an
exception. Does anyone have suggestions on how I can strip the CDATA off of
the string so I can load the real XML into an XmlDocument?


You strip leading "<![CDATA[" and trailing "]]>" before loading string
into XmlDocument.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com
Nov 12 '05 #6

I was hoping for a more integrated approach. I ended up building a regular
expression to strip the CDATA out and that seems to work. Thank you.

Kevin

"Oleg Tkachenko [MVP]" wrote:
Kevin Burton wrote:
I have a string that is returned from a web service that is XML so the string
is enclosed in CDATA[![ . . . ]]. The string/data enclosed in the CDATA
section is real XML. If I try to LoadXml into an XmlDocument I get an
exception. Does anyone have suggestions on how I can strip the CDATA off of
the string so I can load the real XML into an XmlDocument?


You strip leading "<![CDATA[" and trailing "]]>" before loading string
into XmlDocument.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.xmllab.net
http://blog.tkachenko.com

Nov 12 '05 #7
Kevin Burton wrote:

I was hoping for a more integrated approach.
Unfortunately not. Oleg's solution is exactly right. The purpose
of a CDATA section is to prevent the two markup heralds < and &
from being interpreted as markup. Nothing else.

A lot of people use CDATA sections under the impression that they
somehow "protect" the enclosed data. They don't. You would be doing
your suppliers a service if you were to explain that their attempt
to armor their markup was actually interfering with its processing.
I ended up building a regular
expression to strip the CDATA out and that seems to work.


Yep.

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Nov 12 '05 #8
How about this ? I agree with everyone that CDATA is not the right choice
here. Since you don't have control on that,
nothing should stop you adding a wrapper element over it... for example

"<root>" + CDataSection + "</root>"

Now load this into DOM. Let's assume we are using MSXML 4Sp2 and the below
code should work in javascript.

var CDataSection = "<![CDATA[<a>foo</a>]]>";
var dom = new ActiveXObject("MSXML2.DOMDocument.4.0");
dom.async = false;
dom.loadXML("<root>" + CDataSection + "</root>");
dom.loadXML(dom.selectSingleNode("root").text);

WScript.Echo (dom.xml);

Thanks
Pranav Kandula [MSFT]

"Peter Flynn" <pe********@m.silmaril.ie> wrote in message
news:3r************@individual.net...
Kevin Burton wrote:

I was hoping for a more integrated approach.


Unfortunately not. Oleg's solution is exactly right. The purpose
of a CDATA section is to prevent the two markup heralds < and &
from being interpreted as markup. Nothing else.

A lot of people use CDATA sections under the impression that they
somehow "protect" the enclosed data. They don't. You would be doing
your suppliers a service if you were to explain that their attempt
to armor their markup was actually interfering with its processing.
I ended up building a regular
expression to strip the CDATA out and that seems to work.


Yep.

///Peter
--
XML FAQ: http://xml.silmaril.ie/

Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Isaac Councill | last post: by
reply views Thread by Dimitre Novatchev | last post: by
5 posts views Thread by But I Haven't Eaten Any Sweetcorn! | last post: by
2 posts views Thread by Jimmy zhang | last post: by
4 posts views Thread by kplkumar | last post: by
2 posts views Thread by JohnAD | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.