[jdom-interest] XMLOutputter naming questions

Alex Chaffee guru at edamame.stinky.com
Sat Sep 30 16:00:07 PDT 2000

On Sat, Sep 30, 2000 at 03:09:08PM -0700, Joseph Bowbeer wrote:
> Alex Chaffee wrote:
> >> - add a method for outputting a string.  This would just wrap the
> normal output() in a  ByteArrayOutputStream.  Then we can use the same
> formatter (and all its options) to output a (document or element) to a
> (string or stream or writer). <<
> Alex,
> Once you've added output(whatever, Writer), do you need to add extra
> string methods?  Can't the user just pass-in a StringWriter instead?
> I'm not clear on all the encoding complications, but in addition to the
> obligatory toString() method, StringWriter provides getBuffer() to
> return the underlying StringBuffer -- which could be more efficient in
> some situations.

True.  I just feel that people will be asking "How do I turn an
element into a string?" and the easiest way is to answer with a single
method call.  You can always pass in a StringWriter to output() if you

As for encoding, I think Strings are chars are Unicode so encoding is
not an issue.

> If output directly to String is desired, I favor tagging the method name
> with the return type, since Java refuses to differentiate based solely
> on return type.  So if you must, I prefer:
>  String outputString(Document d)
>  String outputString(Element e)
> On the other hand, I don't see any need to append 'Element' as in
> 'outputElement'.  I prefer:
>  void output(Document d, OutputStream out)
>  void output(Element d, OutputStream out)

Thanks for the input.  I agree.

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 mailing list