• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Xml duplication

Hi,

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

Can anyone help?
0
cossy74
Asked:
cossy74
1 Solution
 
nandithaaCommented:
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>" +
                "</book>");

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

    //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);
    Console.WriteLine(shallow.ChildNodes.Count);
    
  }
}

Open in new window


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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now