473,396 Members | 1,738 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,396 software developers and data experts.

Quick question on the presence of CDATA


I have been out of the XML world for a while and have sort of forgotten
the exact difference between:

<Symbol><![CDATA[IBM]]></Symbol>

and just:

<Symbol>IBM</Symbol>

Can anyone tell me why one is preferred over the other?

thanks!

Oct 25 '06 #1
3 1435
Followup to the Microsoft list doesn't work through my servers, so
answering here...
Dilip wrote:
<Symbol><![CDATA[IBM]]></Symbol>
<Symbol>IBM</Symbol>
Identical meaning, since there aren't any special characters in the value.

<!CDATA[]]sections are an alternative to character-by-character
escaping of characters that would otherwise confuse XML syntax (such as
"<" and "&"). It escapes its entire contents -- with the exception of
any ]]sequences, which require special handling.

Generally the only time you care about this is when you're hand-editing
XML, want to drop non-XML text into the value of an XML element (note
that you can't use this kluge for attribute values), and are too lazy to
fix it up by hand. If you build your XML using any XML-aware tool, it
should take care of the escaping for you and you don't have to care
whether it escapes individual characters or uses <!CDATA[]]>
--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Oct 25 '06 #2
Joseph Kesselman wrote:
Followup to the Microsoft list doesn't work through my servers, so
answering here...
Dilip wrote:
<Symbol><![CDATA[IBM]]></Symbol>
<Symbol>IBM</Symbol>

Identical meaning, since there aren't any special characters in the value.

<!CDATA[]]sections are an alternative to character-by-character
escaping of characters that would otherwise confuse XML syntax (such as
"<" and "&"). It escapes its entire contents -- with the exception of
any ]]sequences, which require special handling.

Generally the only time you care about this is when you're hand-editing
XML, want to drop non-XML text into the value of an XML element (note
that you can't use this kluge for attribute values), and are too lazy to
fix it up by hand. If you build your XML using any XML-aware tool, it
should take care of the escaping for you and you don't have to care
whether it escapes individual characters or uses <!CDATA[]]>
Just so that I got this straight, from the standpoint of the XML parser
does the 2 forms of elements make a difference? I mean, if I use XPath
to locate that element to retrieve its value, will I get back IBM or
something else?

Sorry if the question sounds stupid. I remember what CDATA is about
but I have forgotten what happens when a parser encounters it. (It
probably just treats whatever is inside as plain text, right?)

Oct 25 '06 #3
Dilip wrote:
Just so that I got this straight, from the standpoint of the XML parser
does the 2 forms of elements make a difference? I mean, if I use XPath
to locate that element to retrieve its value, will I get back IBM or
something else?
XPath doesn't distinguish the two; both yield IBM.

Parsers *CAN* distinguish the two, for the convenience of editors and
other tools which want to be able to display syntax as well as semantics
-- but aren't required to and often don't unless you ask them to.
probably just treats whatever is inside as plain text, right?)
Modulo the difference in how escaping is handled, yes, pretty much. A
SAX parser may tell the application that it's now inside the bounds of a
CDATA section; the app needs to decide whether to listen for lexical
events and whether it cares about this one. A DOM (depending on how the
builder is configured) may display the data using a CDATASection Node
rather than a Text Node, but the former is a subclass of the latter so
again that doesn't matter unless the application cares about the difference.

As far as the XML Infoset is concerned, <![CDATA[&a<]]is just a
representation of the character sequence &a< and is identical to
&amp;a&lt; or &a< or &#x26;a&#x3c; or any of the other possible
combinations. The Infoset considers the differences between these to be
No Difference.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Oct 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Balaras | last post by:
Hi, Can sombody here please help me a bit with a regular expression. I have a xml file where I need to strip the CDATA sections of any contained data. Eg. <xml> <tag><]></tag>...
8
by: Xah Lee | last post by:
what does it mean when a style tag gives something like the following? <style type="text/css" media="screen,projection">/*<!]>*/</style> is this standard? Xah xah@xahlee.org ∑...
6
by: Cade Perkins | last post by:
How can the CDATA ending delimiter "]]>" be represented within a CDATA section itself? Consider an XML document that is intended to contain an embedded, uninterpreted XML example. Generally,...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
4
by: Jake Barnes | last post by:
I'm reading over this page: http://wiki.script.aculo.us/scriptaculous/show/Usage I'm struck by this code example +++++++++++++++++++++++++++++++ 3. Use
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);...
12
by: Peter Michaux | last post by:
Hi, I am experimenting with some of the Ruby on Rails JavaScript generators and see something I haven't before. Maybe it is worthwhile? In the page below the script is enclosed in //<!]> ...
7
by: Max | last post by:
Hello everyone! Can anyone help me to convert the CDATA expression "CDATA ::= (Char* - (Char* ']]>' Char*)" to Javascript Regular Expression? Thanks, Max
6
by: dkyadav80 | last post by:
Hi sir, I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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,...

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.