Wednesday, October 7, 2009

Example of using XElement to create xml.

Hi,

Here is an example of using XElement to create xml.

The example is building xml, root, nodes and attributes.

The example is very very simple to make it in 2-3 rows

Requirement: Framework 3.5


using System.Xml.Linq;

example:

XElement element = new XElement("root");
element.Add(new XElement("MyNode",
new XAttribute("attr1", "value1"),
new XAttribute("attr2", "value2")));

element.Add(new XElement("MyNode2",
new XAttribute("attr1", "value3"),
new XAttribute("attr2", "value4")));
//xml is ready
element.ToString()

thanks
Rami Heleg,