Creates a new top level element node. - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Creates a new top level element node.

Demo Code

// Permission is hereby granted, free of charge, to any person obtaining
using System.Xml;
using System.Globalization;
using System.Collections.Generic;
using System;/*w w  w. j  av a  2  s.c o  m*/

public class Main{
        /// <summary>
        /// Creates a new top level element node.
        /// </summary>
        /// <param name="name">The element name.</param>
        /// <returns>A new XmlNode</returns>
        public static XmlNode CreateTopLevelElement(string name)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml( "<" + name + "/>" );
            return doc.FirstChild;
        }
}

Related Tutorials