As we know CDATA cannot be nested, so I like to use the solution provided in Using CDATA inside another CDATA that replace ]]>
with ]]]]><![CDATA[>
.
Therefore
<Root>
<![CDATA[
<AAA>
<![CDATA[
<BBB>hello world</BBB>
]]>
</AAA>
]]>
</Root>
becomes
<Root>
<![CDATA[
<AAA>
<![CDATA[
<BBB>hello world</BBB>
]]]]><![CDATA[>
</AAA>
]]>
</Root>
The XML is the response of my API, which will be used by other programs not under my control.
For .NET, my experiment shows that InnerText
can output text in all CDATA sections.
var Root= doc.SelectNode("/Root");
var cdata = Root.InnerText;
cdata is
<AAA>
<![CDATA[
<BBB>hello world</BBB>
]]>
</AAA>
Does the behavior of .NET comply with any standards? Are there any standards saying how to deal with adjacent CDATA? If my API returns adjacent CDATA, will other programs or programming languages have issue processing it?