[英]Cannot parse XML with nested CDATA section
I am having a problem while parsing XML with nested CDATA section. 在解析带有嵌套CDATA部分的XML时遇到问题。 The CDATA section is as below: CDATA部分如下:
<![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 ]]>. 当这种类型的数据出现在XML标记中时,解析XML时会出现错误,因为有两个结束标记]]>。 Can anyone please suggest me what to do or what character should I escape to make this work? 谁能建议我该怎么做,或者我应该逃脱什么角色才能完成这项工作? I am using Java1.8. 我正在使用Java1.8。
The reason you are having trouble parsing this input is that it isn't XML. 您无法解析此输入的原因是它不是XML。 You need to find out what program is generating this non-XML and fix it. 您需要找出什么程序正在生成此非XML并进行修复。
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. 如果要生成XML,则每当您创建一个可能包含序列]]>
的文本节点时(无论它是否表示嵌套CDATA节的结尾),都需要以某种方式对其进行转义。 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 ]]
. 无论发生在哪里,但从技术上讲,仅当>
前面带有]]
时才需要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.