/// <summary> /// Imports a node from another document to the current document. /// </summary> /// <param name="importedNode">The node being imported.</param> /// <param name="deep"><B>True</B> to perform deep clone; otheriwse <B>false</B>.</param> /// <returns>The imported <see cref="DOMNode"/>.</returns> public virtual DOMNode importNode(DOMNode importedNode, bool deep = false) { if (importedNode.IsAssociated) { return(DOMNode.Create(XmlDocument.ImportNode(importedNode.XmlNode, deep))); } else { importedNode.Associate(XmlDocument); return(importedNode); } }
private protected XmlNode CheckedChildOperation(DOMNode /*!*/ newNode, DOMNode auxNode, NodeAction /*!*/ action) { newNode.Associate(XmlNode.OwnerDocument != null ? XmlNode.OwnerDocument : (XmlDocument)XmlNode); // check for readonly node if (XmlNode.IsReadOnly || (newNode.XmlNode.ParentNode != null && newNode.XmlNode.ParentNode.IsReadOnly)) { DOMException.Throw(ExceptionCode.DomModificationNotAllowed); return(null); } // check for owner document mismatch if (XmlNode.OwnerDocument != null ? XmlNode.OwnerDocument != newNode.XmlNode.OwnerDocument : XmlNode != newNode.XmlNode.OwnerDocument) { DOMException.Throw(ExceptionCode.WrongDocument); return(null); } XmlNode result; try { result = action(newNode, auxNode); } catch (InvalidOperationException) { // the current node is of a type that does not allow child nodes of the type of the newNode node // or the newNode is an ancestor of this node. DOMException.Throw(ExceptionCode.BadHierarchy); return(null); } catch (ArgumentException) { // check for newNode == this which System.Xml reports as ArgumentException if (newNode.XmlNode == XmlNode) { DOMException.Throw(ExceptionCode.BadHierarchy); } else { // the refNode is not a child of this node DOMException.Throw(ExceptionCode.NotFound); } return(null); } return(result); }