Numerous ways to do it. Probably the simplest might be written using
Query expression syntax :

---
using System.Xml.Linq;
using System.Collections.Generic;

public static void CopyChildNodes()
{
  XDocument doc1 = XDocument.Load("Test.xml");
  IEnumerable<XElement> elements =
    from el in doc1.Element("Node").Elements("Element")
    select el;

  XDocument doc2 = new XDocument(
    new XDeclaration("1.0", "utf-8", "yes"),
    new XElement("RootNode", elements)
    );

  doc2.Save("Test2.xml");
}
---

On Aug 25, 2:50 am, "musa.biralo" <[email protected]> wrote:
> Hi there,
>
> I have to copy all elements that are within certain node to another
> xml file. Here's an example,
>
> <Node>
>    <Element ID = "1" Attribute="value1" \>
>    <Element ID = "2" Attribute="value2" \>
> .... 1000's of lines...so i like to copy them all
>    <Element ID = "3" Attribute="value3" \>
> </Node>
>
> I want to copy(or transfer) everything that are with in <Node></Node>
> and put it over to other XML file. I could not figure out how. Could
> you please lead to a weblink or help me out.
>
> Thanks in advance.
> Musa.Biralo

Reply via email to