[jdom-interest] Why no containsChild() or containsAttribute()

Xavier Witdouck xavier.witdouck at volbroker.com
Mon Jan 29 06:29:54 PST 2001

Hi Guys,

JDOM's a great piece of work...I do have a question however.  It seems that
the Element class' methods for getChild(String name) and getAttribute(String
name) throw typed exceptions if that child or attribute does not exist.
Since an attribute or child element may be marked #REQUIRED it would seem to
me that throwing an exception in this case is not the right thing to do, as
it is not an error condition.  It would seem more natural to return null if
the child or attribute does not exist????

Another solution would be to provide a containsChild() and
containsAttribute() method on the Element class so that the exception toss
can be avoided....I think checking for NULL should also be documented in the
API on top of these additional "convenience" methods, regardless  I just
joined this list, so I'm sorry if this is a topic that has been beaten to
death, but it really doesn't look right to me...


Xavier Witdouck
Tel: +44 (0)20 7214 4957
Mob: +44 (0)777 568 5877
Email: xavier.witdouck at volbroker.com

More information about the jdom-interest mailing list