[jdom-interest] attributes

Hallvard Tratteberg hal at idi.ntnu.no
Wed Jan 30 13:33:47 PST 2002


Jason,

> elt.getAttribute("foo").setValue("bar") will not drop the existing
attribute reference.
>
> elt.setAttribute(new Attribute("foo", "bar")) of course will do a
replacement.
>
> 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.

I would've thought the latter was equivalent to
Attribute attr = elt.getAttribute("foo");
if (attr != null)
   attr.setValue("bar);
else
   elt.setAttribute(new Attribute("foo", "bar"));

What is the motivation for the "always replace" logic? I don't get it. If
the reasons are good, perhaps we need an ensureAttribute method?

Hallvard




More information about the jdom-interest mailing list