Create Document from root name - CSharp System.Xml

CSharp examples for System.Xml:XML Document

Description

Create Document from root name

Demo Code


using System.Xml;
using System.IO;//w  w  w .ja v  a  2 s  . c  o m

public class Main{
        public static XmlElement CreateDocument(string rootName)
        {
            XmlDocument doc = new XmlDocument();
            
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
            doc.AppendChild(dec);

            XmlElement root = doc.CreateElement(rootName);
            doc.AppendChild(root);

            return root;
        }
}

Related Tutorials