[jdom-interest] Character reference representation

Alastair Rodgers alastair.rodgers at PHOCIS.COM
Thu Dec 20 07:19:57 PST 2001


I have a nicely formatted doc such as: 

<?xml version="1.0" encoding="UTF-8"?>
<Thing>
  <A>
    <Delim>&#10;</Delim>
  </A>
</Thing>  

I want to parse this into a JDOM tree from a text file, make some modifications (e.g. add another element) and then write it back out to a text file. On the parse, the character entity ref &#10; gets interpreted as a carriage return and when I write the doc back out I therefore see: 

<?xml version="1.0" encoding="UTF-8"?>
<Thing>
  <A>
    <Delim>
</Delim>
  </A>
</Thing>  

This is fine for an app to interpret, but for a person its not clear just from looking at the doc which whitespace is relevant and which isn't. 

Is there any straightforward way to force such chars to be represented by their escaped character reference form, i.e. force it to write &#10; on output? 

Thanks, 
Al.



More information about the jdom-interest mailing list