user1356042
user1356042

Reputation: 385

Handling special characters while parsing with JDOM

I have a xml below that I'm parsing with JDOM 2.0.5

<?xml version=\"1.0\" encoding=\"UTF-8\"?><order><BGP1>true</BGP1><BGP2>Metro_C&amp;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

Metro_C&amp;C and not Metro_C&amp;amp;C

Any idea how to resolve this?

Upvotes: 0

Views: 781

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328770

The behavior is correct, your expectation is wrong. The text value of the node is Metro_C&amp;C. When you encode this as XML, the & character must be replaced with &amp; since it has a special meaning for 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&amp;C. Patterns like amp;amp; suggest that someone encoded the data twice.

Upvotes: 2

Related Questions