woezelmann woezelmann - 1 year ago 88
Java Question

SAXReader not re-ecape characters

I'm reading a XML file with dom4j. The file looks like this:

<Field>&#13;&#10; hello, world...</Field>

I read the file with
into a
. When I use
on a the node I obtain the followin String:

\r\n hello, world...

I do some processing and then write another file using
. 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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download