[jdom-interest] getText() and getAttributeValue()

Trimmer, Todd todd.trimmer at trizetto.com
Fri Feb 15 14:01:30 PST 2002

>> p.s. -- I like the element.getAttributeValue(name, defaultValue) idea,

> I don't because it's behavior isn't intuitive without looking at the
> docs.  Example getAttributeValue("drawf","Sleepy"), does this method
> look for a attribute "drawf", then a attribute "Sleepy"?. To me
>    String value = element.getAttributeValue("drawf");
>    if (value == null)
>        value = "Sleepy";

> is preferable because it reads well and clearly shows what the code does.

getAttributeValue("dwarf", "Sleepy") is clear because it looks similar to:

   <!ATTLIST animation dwarf CDATA "Sleepy">

I also strongly disagree that your code reads well. If I had to do 20
attribute reads in a row, my code would be cluttered with those checks. It's
repetitious, arduous, and looks messy. It's better to encapsulate the

Why is getXXX(key, defaultValue) so abhorrent? After seeing Jason Hunter's
ParameterParserClass in Java Servlet Programming, which is chock-full of
methods like this, how can one not appreciate the power and beauty of such a

Todd Trimmer

More information about the jdom-interest mailing list