Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XMLSerialiser: how to keep new/empty lines?

416044Aug 11 2003 — edited Aug 14 2003
how can i tell XMLSerializer to preserve empty lines (and spaces) within elements? i write a DOM object via
FileWriter fw = new FileWriter(file);
OutputFormat of = new OutputFormat(document, "iso-8859-1", true);
of.setLineWidth(0); //turn off automatic line wrapping
of.setPreserveSpace(false); //true preserves new lines but does not nice XML formatting
XMLSerializer xmls = new XMLSerializer(fw,of);
xmls.serialize(document);
and empty lines within text nodes are just ignored or a space is inserted instead. but when i set outputFormat.setPreserveSpace(true), the new lines are preserved and printed to the XML file. however, with setPreserveSpace(true) all the nice XML formatting is gone (all XML is printed to to one single line - just the explicit new lines within elements (text nodes) create new lines), too! :-(

how can i preserve space in element (nodes) but still keep the nice XML formatting (with new lines for each element and indentation)?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 11 2003
Added on Aug 11 2003
4 comments
798 views