[jdom-interest] Feature request: Default values for getters

Matt Sanchez msanchez at liaison.com
Wed Nov 28 09:36:49 PST 2001


As a new user to JDOM, I must admit I am very impressed and pleased to see
such an intuitive interface for XML access.  One thing I have noticed is
that the Element.getText() and Attribute.getXXXValue() methods do not have
versions that allow for default values to be passed in.

For example, it would be nice to be able to do the following:

Element root = doc.getRootElement();
String s = root.getChild("foo").getText("default value");

Element.getText(String default) could be implemented as follows:

public String getText(String default)
{
    String retVal = getText();

    if (retVal.equals(""))
        return default;

    return retVal;
}

Likewise, all the Attribute.getXXXValue() methods could be implemented in a
similar fashion.  I am sure this issue has been brought up before, so please
excuse my ignorance.  Thanks.

Matt B. Sanchez
Software Engineer
Liaison Technology
msanchez at liaison.com

> Powering the e-Catalog content connection
www.liaison.com



More information about the jdom-interest mailing list