System.Xml.XmlDataDocument.CloneNode C# (CSharp) Méthode

CloneNode() private méthode

private CloneNode ( DataPointer dp ) : XmlNode
dp DataPointer
Résultat XmlNode
        private XmlNode CloneNode(DataPointer dp)
        {
            switch (dp.NodeType)
            {
                //for the nodes without value and have no children
                case XmlNodeType.DocumentFragment:
                    return CreateDocumentFragment();
                case XmlNodeType.DocumentType:
                    return CreateDocumentType(dp.Name, dp.PublicId, dp.SystemId, dp.InternalSubset);
                case XmlNodeType.XmlDeclaration:
                    return CreateXmlDeclaration(dp.Version, dp.Encoding, dp.Standalone);

                //for the nodes with value but no children
                case XmlNodeType.Text:
                    return CreateTextNode(dp.Value);
                case XmlNodeType.CDATA:
                    return CreateCDataSection(dp.Value);
                case XmlNodeType.ProcessingInstruction:
                    return CreateProcessingInstruction(dp.Name, dp.Value);
                case XmlNodeType.Comment:
                    return CreateComment(dp.Value);
                case XmlNodeType.Whitespace:
                    return CreateWhitespace(dp.Value);
                case XmlNodeType.SignificantWhitespace:
                    return CreateSignificantWhitespace(dp.Value);
                //for the nodes that don't have values, but might have children -- only clone the node and leave the children untouched
                case XmlNodeType.Element:
                    return CreateElement(dp.Prefix, dp.LocalName, dp.NamespaceURI);
                case XmlNodeType.Attribute:
                    return CreateAttribute(dp.Prefix, dp.LocalName, dp.NamespaceURI);
                case XmlNodeType.EntityReference:
                    return CreateEntityReference(dp.Name);
            }
            throw new InvalidOperationException(SR.Format(SR.DataDom_CloneNode, dp.NodeType.ToString()));
        }

Same methods

XmlDataDocument::CloneNode ( bool deep ) : XmlNode

Usage Example

        public void CloneNode()
        {
            XmlDataDocument doc = new XmlDataDocument();

            doc.DataSet.ReadXmlSchema(new StringReader(RegionXsd));
            doc.Load(new StringReader(RegionXml));

            XmlDataDocument doc2 = (XmlDataDocument)doc.CloneNode(false);

            Assert.Equal(0, doc2.ChildNodes.Count);
            Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-16\"?>", doc2.DataSet.GetXmlSchema().Substring(0, 39));

            doc2 = (XmlDataDocument)doc.CloneNode(true);

            Assert.Equal(2, doc2.ChildNodes.Count);
            Assert.Equal("<?xml version=\"1.0\" encoding=\"utf-16\"?>", doc2.DataSet.GetXmlSchema().Substring(0, 39));

            doc.DataSet.Tables[0].Rows[0][0] = "64";

            Assert.Equal("1", doc2.DataSet.Tables[0].Rows[0][0].ToString());
        }
All Usage Examples Of System.Xml.XmlDataDocument::CloneNode
XmlDataDocument