Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested CDATA Section

 
Nick Bhatt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic