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

Jon Baer jonbaer at digitalanywhere.com
Tue Feb 12 14:01:01 PST 2002


I agree =) + 1

return (attribute == null) ? null : attribute.getValue();
-to-
return (attribute == null) ? "" : attribute.getValue();

- Jon

"Trimmer, Todd" wrote:

> For Element, if no textual content exists, getText() returns an empty
> string. However, if getAttributeValue() is called for an attribute that does
> not exist, null is returned. Why the inconsistency?
>
> Under what circumstances would client code care to differentiate between an
> attribute existing with empty string and the attibute not existing at all?
>
> getAttributeValue() should return empty string if the attribute does not
> exist because:
> 1) It makes it more consistent with getText()
> 2) One won't have to check for null on the return value.
>
> Right now, my code is littered with:
> String name = Parse.assure(elem.getAttributeValue("name"));
> String id = Parse.assure(elem.getAttributeValue("id"));
> // etc.
>
> ...where Parse.assure(String str) returns empty string if str is null; or
> str unchanged if it is non-null. It sure would be nice to get rid of all
> those checks.
>
> Todd Trimmer
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com




More information about the jdom-interest mailing list