[jdom-interest] getText() and getAttributeValue()
jonbaer at digitalanywhere.com
Tue Feb 12 14:01:01 PST 2002
I agree =) + 1
return (attribute == null) ? null : attribute.getValue();
return (attribute == null) ? "" : attribute.getValue();
"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:
More information about the jdom-interest