Nested CDATA - correctly

Eugene Shmorgun picture Eugene Shmorgun · Dec 13, 2012 · Viewed 9.9k times · Source

That's problem in XML document:

<![CDATA[<b>Title</b> 
       Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
       tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
       quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
       consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
       cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
       proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
]]>

I need to insert thу CDATA expression in this text. How to do it ? (I see the error while evaluationg document if I do like this)

<![CDATA[]]]]>Expression<![CDATA[>]]>

Answer

Mike M picture Mike M · Apr 14, 2014

@Oded posted a reference real answer above in a comment... I want to add it as an answer so people can find it.
If he/she adds it we can delete this one.

Yes, it is important to be really sure you need to do this; "CDATA" is often misused in the first place, let alone nested. But in some funky occasions we do.

-

The basic plan is to bury the end of the nested CDATA in another CDATA. It will be stripped with interpretation of the outer CDATA to leave the inner.

This is in the wikipedia article from @Oded above
en.wikipedia.org/wiki/CDATA#Nesting

The action is to replace any inner, nested

]]>

with

]]]]><![CDATA[>