Add XML Node - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Add XML Node

Demo Code


using System.Xml;

public class Main{
        public static XmlNode AddNode(XmlNode parent, string name, string value = null)
        {/* w ww  .j a v  a  2s.c o  m*/
            if (parent == null || string.IsNullOrEmpty(name))
                return null;

            XmlElement element = parent.OwnerDocument.CreateElement(name);

            if (!string.IsNullOrEmpty(value))
            {
                XmlText text = parent.OwnerDocument.CreateTextNode(value);
                element.AppendChild(text);
            }

            return parent.AppendChild(element);
        }
}

Related Tutorials