Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested CDATA - correctly

Tags:

xml

cdata

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[>]]>
like image 641
Eugene Shmorgun Avatar asked Dec 13 '12 17:12

Eugene Shmorgun


1 Answers

@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[>
like image 156
Mike M Avatar answered Sep 19 '22 21:09

Mike M