Changes the
ownerDocument
of a node, its children, as well as the attached attribute nodes if there are any. If the node has a parent it is first removed from its parent child list. This effectively allows moving a subtree from one document to another. The following list describes the specifics for each type of node.
- ATTRIBUTE_NODE
- The
ownerElement
attribute is set to null
and the specified
flag is set to true
on the adopted Attr
. The descendants of the source Attr
are recursively adopted. - DOCUMENT_FRAGMENT_NODE
- The descendants of the source node are recursively adopted.
- DOCUMENT_NODE
Document
nodes cannot be adopted. - DOCUMENT_TYPE_NODE
DocumentType
nodes cannot be adopted. - ELEMENT_NODE
- Specified attribute nodes of the source element are adopted, and the generated
Attr
nodes. Default attributes are discarded, though if the document being adopted into defines default attributes for this element name, those are assigned. The descendants of the source element are recursively adopted. - ENTITY_NODE
Entity
nodes cannot be adopted. - ENTITY_REFERENCE_NODE
- Only the
EntityReference
node itself is adopted, the descendants are discarded, since the source and destination documents might have defined the entity differently. If the document being imported into provides a definition for this entity name, its value is assigned. - NOTATION_NODE
Notation
nodes cannot be adopted. - PROCESSING_INSTRUCTION_NODE, TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE
- These nodes can all be adopted. No specifics.
Note: Unlike the Document.importNode()
method, this method does not raise an INVALID_CHARACTER_ERR
exception and applications should use the Document.normalizeDocument()
method to check if an imported name contain an illegal character according to the XML version in use.
@param source The node to move into this document.
@return The adopted node, or null
if this operation fails, such as when the source node comes from a different implementation.
@exception DOMException NOT_SUPPORTED_ERR: Raised if the source node is of type DOCUMENT
, DOCUMENT_TYPE
.
NO_MODIFICATION_ALLOWED_ERR: Raised when the source node is readonly.
@since DOM Level 3