Share via


IDocument.AdoptNode(INode) Method

Definition

Attempts to adopt a node from another document to this document.

[Android.Runtime.Register("adoptNode", "(Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node;", "GetAdoptNode_Lorg_w3c_dom_Node_Handler:Org.W3c.Dom.IDocumentInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Org.W3c.Dom.INode? AdoptNode (Org.W3c.Dom.INode? source);
[<Android.Runtime.Register("adoptNode", "(Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node;", "GetAdoptNode_Lorg_w3c_dom_Node_Handler:Org.W3c.Dom.IDocumentInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member AdoptNode : Org.W3c.Dom.INode -> Org.W3c.Dom.INode

Parameters

source
INode

The node to move into this document.

Returns

The adopted node, or null if this operation fails, such as when the source node comes from a different implementation.

Attributes

Exceptions

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.

Remarks

Attempts to adopt a node from another document to this document. If supported, it changes the ownerDocument of the source node, its children, as well as the attached attribute nodes if there are any. If the source node has a parent it is first removed from the child list of its parent. This effectively allows moving a subtree from one document to another (unlike importNode() which create a copy of the source node instead of moving it). When it fails, applications should use Document.importNode() instead. Note that if the adopted node is already part of this document (i.e. the source and target document are the same), this method still has the effect of removing the source node from the child list of its parent, if any. The following list describes the specifics for each type of node. <dl> <dt>ATTRIBUTE_NODE</dt> <dd>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.</dd> <dt>DOCUMENT_FRAGMENT_NODE</dt> <dd>The descendants of the source node are recursively adopted.</dd> <dt>DOCUMENT_NODE</dt> <dd> Document nodes cannot be adopted.</dd> <dt>DOCUMENT_TYPE_NODE</dt> <dd> DocumentType nodes cannot be adopted.</dd> <dt>ELEMENT_NODE</dt> <dd><em>Specified</em> attribute nodes of the source element are adopted. 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.</dd> <dt>ENTITY_NODE</dt> <dd> Entity nodes cannot be adopted.</dd> <dt>ENTITY_REFERENCE_NODE</dt> <dd>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.</dd> <dt>NOTATION_NODE</dt> <dd>Notation nodes cannot be adopted.</dd> <dt>PROCESSING_INSTRUCTION_NODE, TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE</dt> <dd>These nodes can all be adopted. No specifics.</dd> </dl> <p ><b>Note:</b> Since it does not create new nodes 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 is not an XML name according to the XML version in use.

Added in DOM Level 3.

Java documentation for org.w3c.dom.Document.adoptNode(org.w3c.dom.Node).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to