xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
- To: xom-interest AT lists.ibiblio.org
- Subject: [XOM-interest] The new Serializer
- Date: Sun, 26 Oct 2003 08:26:57 -0500
I've checked the new Serializer into CVS. You can view it here:
https://xom.dev.java.net/source/browse/xom/src/nu/xom/Serializer.java?rev=1.9&content-type=text/vnd.viewcvs-markup
This is reasonably backwards compatible. If you're just setting a few options on a Serializer and then writing some documents, it behaves the same as it has for the last year. However, there are some new features, and some additional methods intended to make life easier for subclassers.
1. You can instruct the serializer to normalize all data using Unicode Normalization Form C. This includes both text and markup. Normalization is off by default.
2. You can change the serializer's underlying output stream using the new setOutputStream method. This allows programs to use the same options for pretty printing, normalization, and the like on different output streams.
3. There is a new static Serializer.write(document, stream) convenience method that writes the specified document onto the specified output stream using the default options. It makes a lot of simple cases even simpler.
However, this is the one addition I'm least confident of. For one thing it almost calls out for variants that allow different options to be set; e.g. Serializer.write(document, stream, indent); Serializer.write(document, stream, encoding); Serializer.write(document, stream, indent, encoding); etc. This could get out of hand fairly quickly. I'm wondering if this belongs in a separate class, or perhaps should be removed completely.
4. Subclasses can now act at a more granular level using these new protected methods:
writeStartTag
writeEndTag
writeEmptyElementTag
writeXMLDeclaration
writeAttributes
writeNamespaceDeclarations
writeNamespaceDeclaration
Also, I added a protected getColumnCount method that aids subclasses in implementing their own line breaking strategy.
Finally, writePCDATA has been renamed writeEscaped and writeMarkup has been renamed writeRaw because I noticed that in subclasses they weren't always being used for PCDATA and markup respectively. writeMarkup, in particular, was often used to write PCDATA in other formats that needed their own escaping scheme.
Comments are appreciated.
--
Elliotte Rusty Harold
elharo AT metalab.unc.edu
Processing XML with Java (Addison-Wesley, 2002)
http://www.cafeconleche.org/books/xmljava
http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA
- [XOM-interest] The new Serializer, Elliotte Rusty Harold, 10/26/2003
Archive powered by MHonArc 2.6.24.