473,406 Members | 2,345 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,406 software developers and data experts.

CDATA delimiter within CDATA Section

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, the easiest way to represent it would
be to put the embedded XML example inside a CDATA section. But if the
example has a CDATA section itself, then the ending delimiter will be
interpreted as the end of the "real" CDATA section. Here's even a simpler
example with a script's conditional statement:

<test>
<!CDATA[
...
if g[a[i]]>f ...
...
]]>
</test>

This element returns errors when viewed and/or validated in VS.Net and IE 6.
They both interpret the "]]>" within the "if g[a[i]]>f ..." statement as the
end of the CDATA section. Multiple SGML sources on the web indicate that
the above XML should process correctly without change. Others say that the
">" (greater than) should be escaped inside the CDATA section using the
entity reference &gt;. For example:

<test>
<!CDATA[
...
if g[a[i]]&gt;f ...
...
]]>
</test>

But this doesn't work either because entity references are not interpreted
within a CDATA section. That's the whole point of the CDATA section... to
represent literal character data without escapes.

Is it even possible then? Or is this just a bug in all MS XML parsers?
Nov 12 '05 #1
6 8311
* Cade Perkins wrote in microsoft.public.dotnet.xml:
How can the CDATA ending delimiter "]]>" be represented within a CDATA
section itself?


Not possible; you have to split the section.
Nov 12 '05 #2
Two options:
<test>
<![CDATA[
...
if g[a[i]]>]]&gt;<![CDATA[f ...
...
]]>
</test>

And the more readable:
<test>
<![CDATA[
...
if g[a[i]] > f ...
...
]]>
</test>
"Cade Perkins" <ms****@perkcan.net> wrote...
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, the easiest way to represent it would be to put the embedded XML example inside a CDATA section. But if the
example has a CDATA section itself, then the ending delimiter will be
interpreted as the end of the "real" CDATA section. Here's even a simpler
example with a script's conditional statement:

<test>
<!CDATA[
...
if g[a[i]]>f ...
...
]]>
</test>

This element returns errors when viewed and/or validated in VS.Net and IE 6. They both interpret the "]]>" within the "if g[a[i]]>f ..." statement as the end of the CDATA section. Multiple SGML sources on the web indicate that
the above XML should process correctly without change. Others say that the ">" (greater than) should be escaped inside the CDATA section using the
entity reference &gt;. For example:

<test>
<!CDATA[
...
if g[a[i]]&gt;f ...
...
]]>
</test>

But this doesn't work either because entity references are not interpreted
within a CDATA section. That's the whole point of the CDATA section... to
represent literal character data without escapes.

Is it even possible then? Or is this just a bug in all MS XML parsers?

Nov 12 '05 #3
Cade Perkins wrote:
How can the CDATA ending delimiter "]]>" be represented within a CDATA
section itself?
...


Just don't use CDATA as well. Simply escape all "<" as "&lt;" and you're
done.

Nov 12 '05 #4
Julian F. Reschke said:
Just don't use CDATA as well. Simply escape all "<" as "&lt;" and you're
done.


Thanks for the help! This doesn't work for me in my case, but other
responses help me find a reasonable solution. For a few characters, this
fix would be fine, but if I am automating the process and simply want to
store a block of unknown text data, I don't want to have to consider and
replace every possible meta character that I need to escape using entity
references. The CDATA solution would work great except for the inability to
escape the end delimiter. I'm surprised that it is not part of the
specification. I don't understand all the roots of SGML and I imagine it
has an explanation, but every other language/specification I've worked with
allows some way of escaping the delimiter.
Nov 12 '05 #5
Thanks for the help! I'm trying to automate some XML generation, but want
to store literal blocks of text without worrying about having to replace all
possible meta characters with entity references. Although it's not
"pretty", I guess I'll just have to replace all instanced of "]]>" with
"]]>&gt;<![CDATA[" before I place the data in an XML element.

As for the second option (just adding a space), it would probably be great
for the simple example, but other times I wouldn't be able to arbitrarily
add spaces to the data just to make it work.

"Rowland Shaw" <sp********@anotherpointless.org> wrote in message
news:OO**************@TK2MSFTNGP10.phx.gbl...
Two options:
<test>
<![CDATA[
...
if g[a[i]]>]]&gt;<![CDATA[f ...
...
]]>
</test>

And the more readable:
<test>
<![CDATA[
...
if g[a[i]] > f ...
...
]]>
</test>

Nov 12 '05 #6

"Cade Perkins" <ms****@perkcan.net> wrote in message
news:Or**************@tk2msftngp13.phx.gbl...
Julian F. Reschke said:
Just don't use CDATA as well. Simply escape all "<" as "&lt;" and you're
done.
Thanks for the help! This doesn't work for me in my case, but other
responses help me find a reasonable solution. For a few characters, this
fix would be fine, but if I am automating the process and simply want to
store a block of unknown text data, I don't want to have to consider and
replace every possible meta character that I need to escape using entity
references. The CDATA solution would work great except for the inability

to escape the end delimiter. I'm surprised that it is not part of the
specification. I don't understand all the roots of SGML and I imagine it
has an explanation, but every other language/specification I've worked with allows some way of escaping the delimiter.


Do this:
replace all the < and > in your inner xml document to &lt; and &gt; and that
would solve it.
Nov 12 '05 #7

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

Similar topics

2
by: nowhere | last post by:
Hi, I need to preserve some ASCII control characters (CR and LF) within an XML file so I have included the data in a CDATA section. However, when parsing it using expat, I lose the CR...
2
by: Dave Matthews | last post by:
Hi folks, I'm writing a web-page editing tool for my company which will allow staff (with no "technical" expertise) to maintain their own Intranet sites. The content for each webpage is stored...
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 ∑...
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,...
2
by: Steveino | last post by:
Hello, Just wondering if anyone could shed any light on this, it's probably me just being silly... I have a dataset that I've used to create an XmlDataDocument, in order to apply XSL. The XSL...
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 //<!]> ...
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...
1
!NoItAll
by: !NoItAll | last post by:
The MSXML parser is choking on a single character that often appears in my data within a CDATA section. Try this: Dim bRet As Boolean Dim lRet as long Dim xmlDoc As MSXML2.DOMDocument Set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.