Very often, XML parsers will break text elements into multiple character nodes. This is perfectly valid from an XML point of view. So you will need to handle this appropriately. So maybe the problem arises from printing, not the unescaping.
E.g. I can imagine the following XML
<n>A & B</n>
producing the following events:
- begin node
n
- text node "
A
" - text node "
&
" - text node "
B
" - end node
n
Now if you println
every character "thing" you see, you'll get three lines instead of one. Maybe your parser has an option to enforce "normalizing" the events to join succssive text nodes.
(Sorry if I'm not using all the appropriate XML teminiology. My XML terminilogy has become a bit rusty, so feel free to edit this question and put in the correct XML terms. Thank you)