[jdom-interest] (no subject)

Bradley S. Huffman hip at csa.cs.okstate.edu
Thu May 29 08:46:22 PDT 2003


"Robertson, Jason" writes:

> So, just wondering, why doesn't Parent have a getParent() method? 

Blame me :)

All parents can have children (or none), all children can have a parent
(or not), not all parents can also be a child. Documents are always
at the top of the hierarchy and never have a parent and can never be
a child.

> It seems like this would be reasonable given XML's hierarchical layout, i.e.
> if you have a parent it's only one parent so getParent() would be
> unambiguous. Comparatively it doesn't make sense for Child to have something
> like getChild() since going down the tree is much more complex.
> 
> In this one tool I've written I have quite a few places where I do, for
> example
> 
> getParent().getParent().getParent().getAttribute()

Are you sure there will always be 3 parents? Are you really, really sure?
  
Personally I hate this "power user form" because it is so fragile.

> and of course I could replace it with XPath, or this:

Making it robust IMHO.

Brad



More information about the jdom-interest mailing list