add a root element using xmldocument in C#.net

Rakesh kumar picture Rakesh kumar · Jun 18, 2010 · Viewed 16.8k times · Source

I need to create an XML file using an xmldocument object in C#.

How can I add a root element like:

 book:aaaa xsi:schemalocationchemaLocation="http://www.com"

Answer

Matthias picture Matthias · Jun 18, 2010
XmlDocument doc = new XmlDocument();
XmlElement elem = doc.CreateElement("book", "aaaa", "http://www.com");
doc.AppendChild(elem);