[jdom-interest] Setting value of anattribute resets its type
Victor Toni
victor.toni at ebuconnect.de
Fri Apr 7 03:27:40 PDT 2006
After checking the implementation I discovered that the type of an
attribute will be resetted while setting its value (from the Element
class) because a new Attribute object will be created on each modification.
public Element setAttribute(String name, String value) {
return setAttribute(new Attribute(name, value));
}
public Element setAttribute(String name, String value, Namespace ns) {
return setAttribute(new Attribute(name, value, ns));
}
What about:
public Element setAttribute(final String name, final String value) {
final Attribute attribute = getAttribute(name);
if (null == attribute) {
return setAttribute(new Attribute(name, value));
} else {
attribute.setValue(value);
return this;
}
}
public Element setAttribute(final String name, final String value,
final Namespace ns) {
final Attribute attribute = getAttribute(name, ns);
if (null == attribute) {
return setAttribute(new Attribute(name, value, ns));
} else {
attribute.setValue(value);
return this;
}
}
Regards,
Victor
More information about the jdom-interest
mailing list