[jdom-interest] attributes

Jason Hunter jhunter at servlets.com
Wed Jan 30 11:59:49 PST 2002

Here's the logic:

elt.getAttribute("foo").setValue("bar") will not drop the existing
attribute reference.

elt.setAttribute(new Attribute("foo", "bar")) of course will do a

elt.setAttribute("foo", "bar") is a convenience method for the above
syntax, which is why it does a replacement.  One could argue it
shouldn't, and one can argue it should.


Tim Dunnington wrote:
> I had a general question about attributes in the jdom structure.  I've
> noticed that when an attribute is changed, the existing attribute
> reference is dropped and it's replaced with a new one.
> What is the reasoning behind this?
> We are using jdom for a general-purpose tree, with the handy-dandy
> benefit of being able to query and serialize the tree with xpath and
> xml.  However, I'm running into more and more work-arounds to deal
> with the fact that attributes do not persist.
> I intend to override that functionality in my subclassed Element
> object.  I want to make sure I don't have to learn the hard way why
> attributes don't persist in jdom :)
> Thanks,
> Tim

More information about the jdom-interest mailing list