Reputation: 949
I am having a problem while parsing XML with nested CDATA section. The CDATA section is as below:
<![CDATA[*** some text
[ ! <![CDATA[some text]]> ! ]
<![CDATA[some text]]>
]]>
When this type of data is appearing in an XML tag, it is giving an error while parsing the XML as there are two closing tags ]]>. Can anyone please suggest me what to do or what character should I escape to make this work? I am using Java1.8.
Upvotes: 0
Views: 959
Reputation: 163595
The reason you are having trouble parsing this input is that it isn't XML. You need to find out what program is generating this non-XML and fix it.
If you are generating XML, then whenever you create a text node that might contain the sequence ]]>
(whether or not this represents the end of a nested CDATA section) you need to escape it somehow. Many people take the path of least resistance and simply escape >
as >
wherever it occurs, but technically this is needed only if the >
is preceded by ]]
.
Upvotes: 1