Chanmingman's Blog

When you read the article Creating XML Trees in C# (LINQ to XML), http://msdn.microsoft.com/en-us/library/bb387089.aspx, you will see the console output is

 

Child1 was cloned

Child2 was attached

 

You will have a question on why it doesn’t look like the one below.

 

clip_image001[4]

 

In order to get the XML file there are code needs to be added like below.

 

staticvoid Main(string[] args)

{

  //Open the file for XML to write to

  XmlWriter xw = XmlWriter.Create(“output.xml”);

  // Create a tree with a child element.

  XElement xmlTree1 = new XElement(“Root”,

      new XElement(“Child1”, 1)

  );

 

  // Create an element that is not parented.

  XElement child2 = new XElement(“Child2”, 2);

 

  // Create a tree and add Child1 and Child2 to it.

  XElement xmlTree2 = new XElement(

View original post 113 more words

Advertisements