473,566 Members | 3,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8335
* Cade Perkins wrote in microsoft.publi c.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********@ano therpointless.o rg> wrote in message
news:OO******** ******@TK2MSFTN GP10.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******** ******@tk2msftn gp13.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
6478
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 characters. My question is: Should I be using a different character set (not UTF-8) or is this a bug in expat? TIA, Mark
2
7066
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 in the form of XHTML in an XML document (which, in turn, is stored in an XML database). So far so good. However the editing tool must allow users to...
8
4069
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 ∑ http://xahlee.org/
10
42941
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, the XML specification seems a little ambiguous on this, so I defer to the XML authorities. Refer to sections 2.4 and 2.7 (it all hinges on if CDATA...
2
5235
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 reformats the XML to another format (still XML, not HTML). This works fine, but whatever I do, I can't get the finally output section to have CDATA...
12
3969
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 //<!]> Is this trick grounded in any real information about HTML vs XHTML? I
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 create DOM-object, i get the value of "Data" without "\r\n"
1
4077
!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 xmlDoc = New MSXML2.DOMDocument
0
7673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6263
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
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 we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.