Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i write the literal "]]>" inside a CDATA section without it ending the section

Tags:

xml

cdata

Pretty simple question, I'm writing an XML document and i'm not sure how to write "]]>" without it being seen as the end of the section.

like image 886
GBa Avatar asked Feb 11 '09 18:02

GBa


People also ask

Which sequence is not allowed within a CDATA section?

The only sequence which is not allowed within a CDATA section is the closing sequence of a CDATA section itself, ]]> . Note: CDATA sections should not be used within HTML they are considered as comments and not displayed.

What is the correct syntax of CDATA section in an XML document?

A CDATA section begins with the character sequence <! [CDATA[ and ends with the character sequence ]]>. Between the two character sequences, an XML processor ignores all markup characters such as <, >, and &. The only markup an XML pro-cessor recognizes inside a CDATA section is the closing character sequence ]>.

What does <![ CDATA in XML mean?

The term CDATA, meaning character data, is used for distinct, but related, purposes in the markup languages SGML and XML. The term indicates that a certain portion of the document is general character data, rather than non-character data or character data with a more specific, limited structure.

What is the difference between CDATA and Pcdata?

CDATA means the element contains character data that is not supposed to be parsed by a parser. #PCDATA means that the element contains data that IS going to be parsed by a parser.


2 Answers

You can do it like this:

]]>]]&gt;<![CDATA[

This ends up breaking the CDATA section in two parts, but it's what you have to do.

like image 62
Greg Hewgill Avatar answered Oct 26 '22 12:10

Greg Hewgill


I think

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

is the way to go.

That is:

  • one CDATA section containing the literal string ]] (<![CDATA[]]]]>)
  • one CDATA section containing the literal string > (<![CDATA[>]]>)

In practice, there would probably be text before the first ]] and/or after the >

See more at http://en.wikipedia.org/wiki/CDATA#Uses_of_CDATA_sections

like image 36
Henrik Paul Avatar answered Oct 26 '22 12:10

Henrik Paul