[jdom-interest] Thoughts on...
Elliotte Rusty Harold
elharo at metalab.unc.edu
Thu Mar 15 10:31:02 PST 2001
At 4:42 PM +0000 3/15/01, Gary Bentley wrote:
>Hi,
>
>Could I request that there be new methods added to Element so that "text"
>content can be added via primitive types and object. In other words have:
>
> Element.addContent (Object obj);
> Element.addContent (int val);
> Element.addContent (long val);
> Element.addContent (char val);
> Element.addContent (float val);
> Element.addContent (double val);
> Element.addContent (boolean val);
> Element.addContent (char[] vals);
>
>as well as: Element.addContent (String val);
>
>In other words have it similar to how PrintStream works. Currently I have
>to convert all my values myself, which is a pain.
>
May I ask that this not be done? The question of how to properly
convert a binary number such as a double into a decimal number, and
then convert that into a string, is a much more complicated on than
it appears at first glance. It requires significant input from the
programmer as to what they want to happen in many different cases.
The java.text.DecimalFormat class provides a proper APi for this.
PrintStream() does not.
JDOM should not be burdened with the very difficult problem of how to
convert a number to a String. We should let programmers do it as they
see fit in their applications. If a programmer really does just want
the default behavior of PrintStream, then it's straightforward to
write
e.addContent(String.valueOf(x));
or
e.addContent("" + x);
Very little is gained by adding the proposed methods, though they do
make the API larger and more complicated.
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| The XML Bible (IDG Books, 1999) |
| http://metalab.unc.edu/xml/books/bible/ |
| http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://metalab.unc.edu/javafaq/ |
| Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/ |
+----------------------------------+---------------------------------+
More information about the jdom-interest
mailing list