aspose file tools*
The moose likes XML and Related Technologies and the fly likes Nested CDATA Section Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Nested CDATA Section" Watch "Nested CDATA Section" New topic
Author

Nested CDATA Section

Nick Bhatt
Greenhorn

Joined: May 14, 2008
Posts: 6
Hi All,
We have a requirement wherein we need to have nested CDATA in one of our xml messages. I know that this is not possible according to XML specification but there must be someway we can do it? I found a probable solution which splits a CDATA section in twop by using ]]]]><![CDATA[>
in place of ]]>. But is there any other way apart from this?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18908
    
    8

Originally posted by Nick Bhatt:
I know that this is not possible according to XML specification but there must be someway we can do it?
The first part is correct, the XML specification doesn't permit nested CDATA sections. Given that, I don't understand the second part of that sentence.

However you could try clarifying the requirements. You might find they don't really require nested CDATA sections; if they do, you're going to have to redesign.

I can't imagine what real-life situation would cause such a requirement. And if your probable implementation is just using two adjacent CDATA sections (which is perfectly reasonable in XML) then it's possible you misunderstood the requirement. Would you like to post more information about the actual requirement?
M Hammel
Greenhorn

Joined: Nov 27, 2008
Posts: 1
Originally posted by Paul Clapham:
The first part is correct, the XML specification doesn't permit nested CDATA sections.


Almost everything I found on the 'net says the same thing (nested CDATA sections are not allowed). However, the following code seems to dispute that:



The output from running the code is:



(Hopefully this formats okay, I don't see a preview button anywhere)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18908
    
    8

I don't see how it disputes that. The text inside which looks like a CDATA section is just text. It happens to look like a CDATA section, and the way you constructed the node accidentally produces two adjacent CDATA sections which end up evaluating to that text.

So I wouldn't call that "nested CDATA sections". That's why I originally said that I couldn't imagine what nested CDATA sections would look like and asked what the actual requirements were. I expect the requirements went away upon reexamination because we never heard any more from Nick Bhatt.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Nested CDATA Section