Xml duplication


I need to know how to copy the structure of a xmldocument but not its data.

Can anyone help?
Who is Participating?
nandithaaConnect With a Mentor Commented:
Try this:

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

public class Sample
  public static void Main()
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +

    //Create a deep clone.  The cloned node 
    //includes the child node.
    XmlDocument deep = (XmlDocument) doc.CloneNode(true);

    //Create a shallow clone.  The cloned node does not 
    //include the child node.
    XmlDocument shallow = (XmlDocument) doc.CloneNode(false);
    Console.WriteLine(shallow.Name + shallow.OuterXml);

Open in new window

Reference: http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.clonenode%28v=vs.71%29.aspx
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.