[jdom-interest] Element Reference from Attribute

Jason Hunter jhunter at acm.org
Fri Nov 17 13:36:35 PST 2000

> > No, XPath doesn't require that a user can find the Element parent of
> > a returned Attribute.  But it sure does sound useful to me,
> > personally.
> I agree that it sounds useful. Jason can decide if it is the 
> killer use case :-)

I've been thinking about this, and it raises an interesting issue.  What
should the process be to move attributes from one element to another? 
Right now one could have the same Attribute object added to two
different elements, because there's no way for the API to know if an
Attribute is "owned" already or not.  

The problem with this is that setting the value on the new attribute
would also set it on the old attribute at the same time, since they're
the same object.

Solutions are to:

1) Leave it alone with this behavior.

2) Clone any attribute added to an Element.  (No good, because
addAttribute(new Attribute(...)) would do the clone unnecessarily.)

3) Make Attribute immutable.  Remove all set methods.  Then the
Attribute may be added twice, but no one will care.

4) Make Attribute have a parent and use the parent variable to enforce
the same rules for moving attribs as we have for Element.

The same issues exist for Comment, PI, and perhaps others.  Thoughts?


More information about the jdom-interest mailing list