Setting value of anattribute resets its type 2006-04-07 - By Victor Toni
Back 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 __ ____ ____ ____ ____ ____ ____ ____ ____ ____ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
|
|