I'm reading a XML file with dom4j. The file looks like this:
...
<Field> hello, world...</Field>
...
I read the file with SAXReader
into a Document
. When I use getText()
on a the node I obtain the followin String:
\r\n hello, world...
I do some processing and then write another file using asXml()
. But the characters are not escaped as in the original file which results in error in the external system which uses the file.
How can I escape the special character and have
when writing the file?
You cannot easily. Those aren't 'escapes', they are 'character entities'. They are a fundamental part of XML. Xerces has some very complex support for 'unparsed entities', but I doubt that it applies to these, as opposed to the species that are defined in a DTD.