Create XML Document - CSharp System.Xml

CSharp examples for System.Xml:XML Document

Description

Create XML Document

Demo Code


using System.Xml;

public class Main{
        public static XmlDocument CreateDocument(string rootName)
        {//from   ww  w.  j a  v  a 2 s  . c  om
            if (string.IsNullOrEmpty(rootName))
                return null;

            var document = new XmlDocument();
            document.InsertBefore(document.CreateXmlDeclaration("1.0", "UTF-8", null), document.DocumentElement);
            document.AppendChild(document.CreateElement(rootName));

            return document;
        }
}

Related Tutorials