javaxmljdom

Jdom 1.1.1 - Ampersand problems?


currently i am debugging and older application for parsing XML Files.

I've noticed, that when I have an element, such as:

<value type="String">Hans &amp; Meiser</value>

I'd expect in the extraction code (iterating over all elements), when calling

Object value = element.getText()

that the text results in:

Hans & Meiser

but instead of getting the expected result, it seems like that the spaces before and after the ampersand are removed (by jdom)

Hans&Meiser

This happens with all entities.

Further, the wrapping of the value within CDATA wasn't successful, too:

<value type="String"><![CDATA[Hans & Meiser]]></value>

Same issue with CDATA.


Solution

  • This issue is solved, since it is not a jdom issue. Further analysis leads to the point, that the issue is related to the XMLStreamReader, for which the solution can be found here:

    Reading escape characters with XMLStreamReader