I am trying to create CDATA section within the description field, but failing. The code is pretty simple, but in the resulting XML a CDATA section does not appear!!
Node de = document.createElement("description");
de.appendChild(document.createCDATASection(reportData.getIssue().getDescription() + "more]]>data"));
e.appendChild(de);
In the result XML, I’m getting:
<description>Room #1128 has AD issues.more]]>data</description>
What am I doing wrong?!
The sequence
]]>terminates a CDATA section and thus cannot appear within a CDATA section.Your XML library is recovering by ditching the CDATA section and using entities for characters that would have special meaning.
Since
<foo><![CDATA[Hello, world>]]></foo>and<foo>Hello, world></foo>are equivalent, this isn’t a problem (unless someone tries to parse the resulting XML with a tool that isn’t an XML parser, which way lies madness).