public virtual XmlNode ImportNode(XmlNode node, bool deep) { if (node == null) { throw new NullReferenceException("Null node cannot be imported."); } switch (node.NodeType) { case XmlNodeType.Attribute: XmlAttribute srcAtt = node as XmlAttribute; XmlAttribute dstAtt = this.CreateAttribute(srcAtt.Prefix, srcAtt.LocalName, srcAtt.NamespaceURI); for (XmlNode n = srcAtt.FirstChild; n != null; n = n.NextSibling) { dstAtt.AppendChild(this.ImportNode(n, deep)); } return(dstAtt); case XmlNodeType.CDATA: return(this.CreateCDataSection(node.Value)); case XmlNodeType.Comment: return(this.CreateComment(node.Value)); case XmlNodeType.Document: throw new XmlException("Document cannot be imported."); case XmlNodeType.DocumentFragment: XmlDocumentFragment df = this.CreateDocumentFragment(); if (deep) { for (XmlNode n = node.FirstChild; n != null; n = n.NextSibling) { df.AppendChild(this.ImportNode(n, deep)); } } return(df); case XmlNodeType.DocumentType: return(((XmlDocumentType)node).CloneNode(deep)); case XmlNodeType.Element: XmlElement src = (XmlElement)node; XmlElement dst = this.CreateElement(src.Prefix, src.LocalName, src.NamespaceURI); for (int i = 0; i < src.Attributes.Count; i++) { XmlAttribute attr = src.Attributes [i]; if (attr.Specified) // copies only specified attributes { dst.SetAttributeNode((XmlAttribute)this.ImportNode(attr, deep)); } } if (deep) { for (XmlNode n = src.FirstChild; n != null; n = n.NextSibling) { dst.AppendChild(this.ImportNode(n, deep)); } } return(dst); case XmlNodeType.EndElement: throw new XmlException("Illegal ImportNode call for NodeType.EndElement"); case XmlNodeType.EndEntity: throw new XmlException("Illegal ImportNode call for NodeType.EndEntity"); case XmlNodeType.EntityReference: return(this.CreateEntityReference(node.Name)); case XmlNodeType.None: throw new XmlException("Illegal ImportNode call for NodeType.None"); case XmlNodeType.ProcessingInstruction: XmlProcessingInstruction pi = node as XmlProcessingInstruction; return(this.CreateProcessingInstruction(pi.Target, pi.Data)); case XmlNodeType.SignificantWhitespace: return(this.CreateSignificantWhitespace(node.Value)); case XmlNodeType.Text: return(this.CreateTextNode(node.Value)); case XmlNodeType.Whitespace: return(this.CreateWhitespace(node.Value)); case XmlNodeType.XmlDeclaration: XmlDeclaration srcDecl = node as XmlDeclaration; return(this.CreateXmlDeclaration(srcDecl.Version, srcDecl.Encoding, srcDecl.Standalone)); default: throw new InvalidOperationException("Cannot import specified node type: " + node.NodeType); } }
public override XmlNode CloneNode(bool deep) { XmlNode n = new XmlProcessingInstruction(target, data, OwnerDocument); return(n); }