[jdom-interest] Missing setAttribute in Element

Bernard D'Have bdha at SpiritSystems.be
Sun Mar 25 13:44:48 PST 2001


While reviewing my actual code for a project that use heavily JDOM, I see a
lot of code like this:

protected void setAttribute(Element e, String attributeName, Object
attribute Value) {
  Attribute a= e.getAttribute(attributeName);
  if (a==null) {
    a= new Attribute(attributeName, attributeValue);
    e.addAttribute(a);
  } else {
    a.setValue(attributeValue);
  }
}

It seems that a method like this is missing in Element class:

public Element setAttribute(String attributeName, String attributeValue) {
  Attribute a= getAttribute(attributeName);
  if (a==null) {
    a= new Attribute(attributeName, attributeValue);
    addAttribute(a);
  } else {
    a.setValue(attributeValue);
  }
  return this;
}

I think this method is more usual than check first if the attribute is
present.
Any opinions?


Bernard D'Havé
Software Engineer

Spirit Systems
e-mail: mailto:bdha at SpiritSystems.be




More information about the jdom-interest mailing list