[jdom-interest] How to keep input - formatting.. Linebreaks

Elliotte Rusty Harold elharo at metalab.unc.edu
Fri Nov 14 07:25:37 PST 2003


At 3:07 PM +0100 11/14/03, Morten Andersen wrote:
I'm building a document using SAXBuilder, and I want to keep the line 
breaks in the text-content of an attribute on one of the elements. 
How do I do that?

Example:
-----------------------------
<?xml version="1.0" encoding="UTF-8"?>
<page><part edit="false" text="dsdsfd"><view>dsdsfd&lt;br/&gt;
</view></part><part text="dfsfs

*Hello
*Hello again">

</part></page>
-------------------------------------
How can I keep the linebreaks from the source XML-file into the jdom Element?


You can't; not really. This is a known design flaw in XML. As Tim 
Bray wrote on Juen 20, "we screwed up in letting attribute 
normalization into XML.  It still boggles my mind in retrospect that 
during the discussions back in 96-97,  nobody piped up to say 'why 
are you morons doing this?'  Because we probably would have said 
'D'oh, right, lose it.'  Sigh."

JDOM can't do much about it. The best you can do is escape your line 
breaks as &#x0A; or &#x0D;. Then the parser won't normalize them on 
input.
-- 

   Elliotte Rusty Harold
   elharo at metalab.unc.edu
   Effective XML (Addison-Wesley, 2003)
   http://www.cafeconleche.org/books/effectivexml
   http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA



More information about the jdom-interest mailing list