473,389 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 software developers and data experts.

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 14286
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
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
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
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
by: Jimmy zhang | last post by:
Are they teh same thing in xml 1.0?
11
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
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
by: kplkumar | last post by:
After serialzing I want, <MyRequest> <Content SigningScheme="pkcs7"><!]></Content> </MyRequest> _________________________________________________________________________________________ ...
2
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...
0
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...

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.