[XOM-interest] XML pretty printer

Luca Passani passani at eunet.no
Mon Jul 23 04:46:49 EDT 2007


Hi, I have built myself an utility to manage a rather large XML file. 
What the utility does is to load the file, manipulate the OM and, 
finally, spit out XML again the usual way.

    public static void toPrettyXML(Document doc, OutputStream out) 
throws Exception {
    Serializer serializer = new Serializer(out);
    serializer.setIndent(2);
    serializer.setMaxLength(200);
    serializer.setPreserveBaseURI(false);
    serializer.write(doc);
    serializer.flush();
    out.close();
    }

it all looked very good, until users of my project came back and told me 
that what looked like this before (observe empty line between the two 
elements):

<device>
  :
</device>

<device>
  :
</device>

Now looks like this:

<device>
  :
</device>
<device>
  :
</device>


which impacts readibility (it's a 5Meg file, but still assumed to be 
readable to humans!).

Is there a way to fix this with the XOM serializer/pretty printer? of 
course, I only want th extra line to apply to the "device" element and 
not to others.

Thanks

Luca
 





More information about the XOM-interest mailing list