Java – creating CDATA sections is confusing

I tried to create a CDATA section in the description field, but failed The code is very simple, but there is no CDATA part in the generated XML!

Node de = document.createElement("description");
de.appendChild(document.createCDATASection(reportData.getIssue().getDescription() + "more]]>data"));
e.appendChild(de);

In the result XML, I get:

<description>Room #1128 has AD issues.more]]&gt;data</description>

What on earth did I do wrong?!

Solution

Sequence]] > terminates the CDATA section and therefore cannot appear in the CDATA section

Your XML library is recovering by discarding the CDATA section and using entities to recover characters with special meaning

Because < foo > ]] > < / foo > and < foo > Hello, world & gt; equivalence, which is not a problem (unless someone tries to parse the generated XML with a tool other than an XML parser, this method is crazy)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>