Creates a duplicate of this node. : XmlElement « XML « C# / C Sharp






Creates a duplicate of this node.

   

using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {

    XmlDocument doc = new XmlDocument();
    doc.Load("data.xml");

    XmlElement elem = doc.CreateElement("misc");
    elem.InnerText = "hardcover";
    elem.SetAttribute("publisher", "A");

    XmlNode elem2 = elem.CloneNode(true);

    doc.DocumentElement.FirstChild.AppendChild(elem);
    doc.DocumentElement.LastChild.AppendChild(elem2);

    doc.Save(Console.Out);

  }
}

   
    
    
  








Related examples in the same category

1.Gets an XmlAttributeCollection containing the list of attributes
2.Returns the value for the attribute with the specified name.
3.Returns the XmlAttribute with the specified name.
4.Returns an XmlNodeList containing a list of all descendant elements that match the Name.
5.Gets a boolean value indicating whether the current node has any attributes.
6.Gets or sets the concatenated values of the node and all its children.Gets or sets the concatenated values of the node and all its children.
7.Gets or sets the tag format of the element.
8.Gets the local name of the current node.
9.Gets the qualified name of the node.
10.Gets the XmlDocument to which this node belongs.
11.Removes all specified attributes and children of the current node. Default attributes are not removed.
12.Removes all specified attributes from the element.
13.Removes an attribute by name.
14.Removes an attribute with the specified local name and namespace URI.
15.Removes the attribute node with the specified index from the element.
16.Removes the XmlAttribute specified by the local name and namespace URI.
17.Adds the specified XmlAttribute.
18.Saves all the children of the node to the specified XmlWriter.
19.Saves the current node to the specified XmlWriter.
20.Load Xml String
21.Creates the element.
22.Get first child and its Node List
23.Append element
24.Appends a new empty element to the given target element.
25.Appends a new element containing a text value to the given target element.