[英]Handling special characters while parsing with JDOM
I have a xml below that I'm parsing with JDOM 2.0.5 我下面有一个要用JDOM 2.0.5解析的xml
<?xml version=\"1.0\" encoding=\"UTF-8\"?><order><BGP1>true</BGP1><BGP2>Metro_C&amp;C</BGP2></order>
Now while trying to get the value of the tag using node.getValue() where node is of type Element, it's giving me the node value as 现在,当尝试使用node.getValue()获取标签的值(其中node是Element类型)时,它给我的节点值为
Metro_C&C and not Metro_C&amp;C
Any idea how to resolve this? 任何想法如何解决这个问题?
The behavior is correct, your expectation is wrong. 行为正确,您的期望是错误的。 The text value of the node is
Metro_C&C
. 节点的文本值为
Metro_C&C
When you encode this as XML, the &
character must be replaced with &
当您将其编码为XML时,必须用
&
替换&
字符&
since it has a special meaning for XML. 因为它对XML有特殊的意义。
But my feeling is that the input data is already corrupt. 但是我的感觉是输入数据已经损坏。 The text value should probably be
Metro_C&C
which would give the XML encoded value of Metro_C&C
. 文本值可能应该是
Metro_C&C
,它将提供Metro_C&C
的XML编码值。 Patterns like amp;amp;
像
amp;amp;
suggest that someone encoded the data twice. 建议有人对数据进行两次编码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.