CDATA部分的创建令人困惑 [英] Creation of CDATA section is confusing
问题描述
我正在尝试在description字段中创建CDATA部分,但是失败了。代码很简单,但是在生成的XML中没有出现CDATA部分!
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);
在XML结果中,我得到:
In the result XML, I'm getting:
<description>Room #1128 has AD issues.more]]>data</description>
我在做什么错了?!
推荐答案
序列]] >>
终止CDATA部分,因此不能出现在CDATA部分中。
The sequence ]]>
terminates a CDATA section and thus cannot appear within a CDATA section.
通过放弃CDATA节并使用具有特殊含义的字符的实体来恢复XML库。
Your XML library is recovering by ditching the CDATA section and using entities for characters that would have special meaning.
由于< foo><![CDATA [Hello,world>]]>< / foo>
和< foo> Hello,world& gt; / foo>
是等效的,这不是问题(除非有人尝试使用不是XML解析器的工具来解析生成的XML,这就是疯狂的手段。)
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).
这篇关于CDATA部分的创建令人困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!