473,497 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14291
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1983
by: Isaac Councill | last post by:
Hello, This seems like a newbie question, but I couldn't find the answer on google. I've been using xsl to transform rdf files into runnable programs in another (non-markup) language. It's...
0
2071
by: Dimitre Novatchev | last post by:
You seem to be unaware of the xslt processing which uses the built-in rules in the absence of templates that match some selected node. http://www.w3.org/TR/xslt#built-in-rule According to the...
5
7427
by: But I Haven't Eaten Any Sweetcorn! | last post by:
Hi all, I have two XML DOMs and I am trying to insert one into another, so that <?xml = ....> <Body> <Head> </Head> </Body> and
2
1762
by: Jimmy zhang | last post by:
Are they teh same thing in xml 1.0?
11
6421
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
1
4011
by: soccerdad | last post by:
I've got a class hierarchy generated from a .xsd schema file using the XSD.EXE tool. One of the elements will have its "inner text" set to a CDATA block. The XSD.EXE tool exposed a "Value" property...
4
9061
by: kplkumar | last post by:
After serialzing I want, <MyRequest> <Content SigningScheme="pkcs7"><!]></Content> </MyRequest> _________________________________________________________________________________________ ...
2
5906
by: JohnAD | last post by:
Hello NG, I am getting some information from DB, and that data has mix html and XML tags in the content (e.g. detail on country). Basically CDATA types are mixed with regular string. Also,...
18
758
by: sim.sim | last post by:
Hi all. i'm faced to trouble using minidom: #i have a string (xml) within CDATA section, and the section includes "\r\n": iInStr = '<?xml version="1.0"?>\n<Data><!]></Data>\n' #After i...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6881
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.