Rename an existing node of type
ELEMENT_NODE or
ATTRIBUTE_NODE.
When possible this simply changes the name of the given node, otherwise this creates a new node with the specified name and replaces the existing node with the new node as described below.
If simply changing the name of the given node is not possible, the following operations are performed: a new node is created, any registered event listener is registered on the new node, any user data attached to the old node is removed from that node, the old node is removed from its parent if it has one, the children are moved to the new node, if the renamed node is an
Element its attributes are moved to the new node, the new node is inserted at the position the old node used to have in its parent's child nodes list if it has one, the user data that was attached to the old node is attached to the new node.
When the node being renamed is an
Element only the specified attributes are moved, default attributes originated from the DTD are updated according to the new element name. In addition, the implementation may update default attributes from other schemas. Applications should use
Document.normalizeDocument() to guarantee these attributes are up-to-date.
When the node being renamed is an
Attr that is attached to an
Element, the node is first removed from the
Element attributes map. Then, once renamed, either by modifying the existing node or creating a new one as described above, it is put back.
In addition,
- a user data event
NODE_RENAMED is fired,
- when the implementation supports the feature "MutationNameEvents", each mutation operation involved in this method fires the appropriate event, and in the end the event {
http://www.w3.org/2001/xml-events, DOMElementNameChanged} or { http://www.w3.org/2001/xml-events, DOMAttributeNameChanged} is fired.