I had thought about this and I guess never got to fix it. Copying all the flags isn't the right thing to do. On the other hand the two other proposals sound good to me. -- Arnaud Le Hors - IBM, XML Standards Strategy Group / W3C AC Rep.
> -----Original Message----- > From: Michael Gratton [mailto:[EMAIL PROTECTED] > Sent: Wednesday, August 20, 2003 9:40 PM > To: [EMAIL PROTECTED] > Subject: importNode() / adoptNode() breaks getElementById() > > > > Hi guys, > > I'm looking for some feedback on the correct way to fix a bug with > importNode() and adoptNode(). Let me explain the bug first. > > I want to copy or move some elemets from one document (docA) into > another (docB). The elements in question have an IDREF attribute set on > them, and using Document.getElementbyId() on docA works as expected. > However after importing the elements into docB using either importNode() > or adoptNode(), calling getElementbyId() on DocB fails to return the > imported/adopted elements. > > The importNode() method copies attributes by constructing new instances > of the attribute node with Document.createAttribiute[NS](). Hence the > NodeImpl.ID flag on the attribute is not preserved and so when > importNode() calls setNodeValue() to set the copied attribute's value, > AttrImpl.setNodeValue() does not end up calling putIdentifier() on it's > ownerDocument as it should. > > Would a correct fix for this be to copy NodeImpl.flags across to the new > attribute when the source attribute is also an instance of NodeImpl? Or > perhaps examine isIdAttribute() on the original and set it accordingly > on the copy? > > The adoptNode() method does preserve the NodeImpl.ID flag, but does not > do anything to cause the identifier to be removed from the old owner > document and be added to the new owner document. > > A potential fix for this would be in AttrImpl.setOwnerDocument(), when > the NodeImpl.ID flag is set, to call removeIdentifier() on the existing > owner document, if any, and to call putIdentifier() on the new owner > document, if any. > > Thanks for your comments! > > Mike. > > -- > Mike Gratton <jabber:[EMAIL PROTECTED]> <http://web.vee.net/> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
