xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: dirk bergstrom <dirk AT juniper.net>
- To: elharo AT metalab.unc.edu
- Cc: xom-interest <xom-interest AT lists.ibiblio.org>
- Subject: [XOM-interest] A small request
- Date: Tue, 06 Jan 2004 15:41:59 -0800
I recently discovered that I need to preserve whitespace in my xml config
files. I dutifully added the following to my code (I like to be explicit):
serializer.setIndent(0);
serializer.setMaxLength(0);
And everything seemed right in the world.
That is, until I needed to diff a couple of files, and the diffs were
*huge*. A ten character change made for a diff bigger than the file,
because the whole file was one long line.
I appreciate that whitespace has been scrupulously preserved, but the
document is no longer really human-readable.
My documents have no mixed content -- elements contain either text, or other
elements, but never both. This means that adding a linebreak after each
close tag restores readability (and diff-ability).
I suspect that a large number of users will find themselves in a similar
situation to mine, needing to preserve whitespace inside tags, while keeping
the overall document legible. It would be nice to have a convenience method
for this, something along the lines of setBreakAfterCloseTag(boolean).
Otherwise, you need to write a subclass like this:
private static class BreakingSerializer extends Serializer {
public BreakingSerializer(OutputStream out, String encoding)
throws UnsupportedEncodingException {
super(out, encoding);
}
protected void writeCloseTag(Element element)
throws IOException {
super.writeCloseTag(element);
breakLine();
}
protected void writeEmptyElementTag(Element element)
throws IOException {
super.writeEmptyElementTag(element);
breakLine();
}
}
I know that you're opposed to spurious convenience methods, but I think that
the effort required to implement the solution is sufficiently high (19
lines), that it would be worthwhile.
Thanks.
--
Dirk Bergstrom dirk AT juniper.net
_____________________________________________
Juniper Networks Inc., Computer Geek
Tel: 408.745.3182 Fax: 408.745.8905
-
[XOM-interest] A small request,
dirk bergstrom, 01/06/2004
-
Re: [XOM-interest] A small request,
Elliotte Rusty Harold, 01/06/2004
- Re: [XOM-interest] A small request, dirk bergstrom, 01/06/2004
-
Re: [XOM-interest] A small request,
Elliotte Rusty Harold, 01/06/2004
Archive powered by MHonArc 2.6.24.