<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.3211.1700" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>I had a few problems with
Element.addAttribute() in that it didn't update/replace old attributes, I
looked at the latest source from the CVS snapshot and the problem was still
there. I took a few minutes and poked around and here is what I came up
with (I just tested for my simple case, but it seemed to work). I simply
call removeAttribute() if the attribute already exists. Maybe someone will
verify this, and if it works check it in.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>Robert r. Sanders</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> /**<BR> * <p><BR> * This
adds an attribute to this element. Any existing attribute with<BR> *
the same name and namespace URI is removed.<BR> * </p><BR>
*<BR> * @param attribute <code>Attribute</code> to
add<BR> * @return this element modified<BR> */<BR> public
Element addAttribute(Attribute attribute) {<BR> if
(getAttribute(attribute.getName(), attribute.getNamespace()) != null)
{<BR> if (! removeAttribute(attribute.getName(),
attribute.getNamespace() ) ) {<BR> throw new
IllegalAddException(this, attribute, "Duplicate attributes are not allowed,
unable to remove old
Attribute.");<BR> }<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> if (attribute.getParent() != null)
{<BR> throw new IllegalAddException(this,
attribute,<BR> "The attribute already has an existing
parent \"" +<BR> attribute.getParent().getQualifiedName()
+ "\"");<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> // XXX Should verify attribute ns
prefix doesn't collide with<BR> // another attribute prefix or this
element's prefix</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2> if (attributes == null)
{<BR> attributes = new
LinkedList();<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial
size=2> attributes.add(attribute);<BR> attribute.setParent(this);<BR> return
this;<BR> }</FONT></DIV></BODY></HTML>