[jdom-interest] Ampersand question
guru at edamame.stinky.com
Thu Jul 13 06:12:51 PDT 2000
> Therefore I want to take all the code in
> XMLOutputter that's dedicated to converting JDOM objects to strings
> and put it in XMLSerializer. This means that anybody who only wants
> strings (e.g. for debugging) won't have to worry about encoding
> issues. And we can make XMLSerializer guaranteed correct.
> XMLOutputter will take care of moving the strings onto an output
> stream or writer as necessary. It will delegate all the detailed
> formatting of objects as strings to XMLSerializer.
> You know, I was trying to think of a better name than XMLSerializer
> for the class since it really has nothing to do with object
> serialization. Maybe I should call it XMLFormat, and change the
> serialize() methods to format() methods.
That sounds very good (really!) except for one thing:
For performance reasons, you will want to be able to format() directly
onto a stream or writer, rather than suffering the waste of
intermediate Strings and/or StringBuffers.
Given that, I'm afraid that the cleanest solution is to merge the two
into one like I suggested before. If you really want to separate ugly
encoding and IO logic from nice clean formatting logic, then it might
be possible to do some behind-the-scenes factoring, say making a
package-accessible XMLFormat class that provides implementation
methods for the formatting interfaces, but writes to a stream by
default anyway. No promises though :-)
> In essence, I'm paralleling
> the DecimalFormat/OutputStream distinction that Java uses for writing
> numbers into text files and the console.
The *Format classes are also rife with string droppings. :-( Though at
least they append to a StringBuffer at heart, rather than returning a
String, which mitigates it somewhat.
If only the whole universe were pure and Unicode...
Alex Chaffee mailto:alex at jguru.com
jGuru - Java News and FAQs http://www.jguru.com/alex/
Creator of Gamelan http://www.gamelan.com/
Founder of Purple Technology http://www.purpletech.com/
Curator of Stinky Art Collective http://www.stinky.com/
More information about the jdom-interest