You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Steve Dickson <sd...@savagesoftware.com> on 2000/03/30 03:08:45 UTC

ElementImpl::setAttribute()

Using the xerces C++ source drop, ElementImpl.cpp Revision 1.9 2000/03/02

In ElementImpl::setAttribute(), a new AttrImpl object is created,
populated and then inserted into ElementImpl::attributes using
NamedNodeMapImpl::setNamedItem().   If an item with the same name already
exists in the NamedNodeMap, it is replaced by the newly created item and
deleted (pending reference counting).  

Wouldn't it be more effective to check whether an attribute of this name
exists first and, if so, repopulate it with the new data?  Is there some
compelling reason why the method was not implemented this way?

The reason I ask is that I am working on a project in which we extend
AttrImpl (among other classes).  The current implementation of
ElementImpl::setAttribute() causes problems since it replaces our objects
which extend AttrImpl with AttrImpl base objects.  This problem would
disappear if an existence check was made before creating a new object.  As
a workaround, we override setAttribute() with our own implementation.

Is there any chance that this method will be revisited in newer revisions?

S.




Re: ElementImpl::setAttribute()

Posted by Andy Heninger <he...@us.ibm.com>.
Implementing setAttribute in the way you suggest should be fine.

And, you could read the DOM spec as requiring it, although it is not
completely clear.  It says setAttribute "Adds a new attribute. If an
attribute with that name is already present in the element, its value is
changed to be that of the value parameter."  See
http://www.w3.org/TR/DOM-Level-2/core.html#ID-745549614

If you'd like to go ahead and make the change, mail the patch back to this
list and I'll put it in.

   -- Andy


----- Original Message -----
From: "Steve Dickson" <sd...@savagesoftware.com>

> In ElementImpl::setAttribute(), a new AttrImpl object is created,
> populated and then inserted into ElementImpl::attributes using
> NamedNodeMapImpl::setNamedItem().   If an item with the same name already
> exists in the NamedNodeMap, it is replaced by the newly created item and
> deleted (pending reference counting).
>
> Wouldn't it be more effective to check whether an attribute of this name
> exists first and, if so, repopulate it with the new data?  Is there some
> compelling reason why the method was not implemented this way?
>