diff --git a/include/DOM/Simple/AttrMap.hpp b/include/DOM/Simple/AttrMap.hpp index cb062da2..8bc5a215 100644 --- a/include/DOM/Simple/AttrMap.hpp +++ b/include/DOM/Simple/AttrMap.hpp @@ -65,10 +65,13 @@ class AttrMap : public NamedNodeMapImpl } // setAttributeNode virtual DOMNode_implT* setNamedItem(DOMNode_implT* newAttr) { + AttrImplT* attr = dynamic_cast(newAttr); + if(alreadyHere(attr)) + return attr; NamedNodeMapImplT::throwIfReadOnly(); - checkNotInUse(newAttr); - dynamic_cast(newAttr)->setOwnerElement(ownerElement_); - return dynamic_cast(NamedNodeMapImplT::setNamedItem(newAttr)); + checkNotInUse(attr); + attr->setOwnerElement(ownerElement_); + return dynamic_cast(NamedNodeMapImplT::setNamedItem(attr)); } // setNamedItem DOMAttr_implT* removeAttributeNode(DOMAttr_implT* oldAttr) @@ -113,9 +116,12 @@ class AttrMap : public NamedNodeMapImpl } // setAttributeNodeNS virtual DOMNode_implT* setNamedItemNS(DOMNode_implT* newAttr) { + AttrImplT* attr = dynamic_cast(newAttr); + if(alreadyHere(attr)) + return attr; NamedNodeMapImplT::throwIfReadOnly(); - checkNotInUse(newAttr); - dynamic_cast(newAttr)->setOwnerElement(ownerElement_); + checkNotInUse(attr); + attr->setOwnerElement(ownerElement_); return dynamic_cast(NamedNodeMapImplT::setNamedItemNS(newAttr)); } // setNamedItem @@ -193,10 +199,14 @@ class AttrMap : public NamedNodeMapImpl return 0; } // getDefaultAttrs - void checkNotInUse(DOMNode_implT* newAttr) + bool alreadyHere(AttrImplT* attr) + { + return ((!attr->isOrphaned()) && (attr->getOwnerElement() == ownerElement_)); + } // alreadyHere + + void checkNotInUse(AttrImplT* attr) { - AttrImplT* attr = dynamic_cast(newAttr); - if(!attr->isOrphaned()) + if((!attr->isOrphaned()) && (attr->getOwnerElement() != ownerElement_)) throw DOM::DOMException(DOM::DOMException::INUSE_ATTRIBUTE_ERR); } // checkNotInUse