Adds the XML child. - CSharp System.Xml

CSharp examples for System.Xml:XML Child

Description

Adds the XML child.

Demo Code


using System.Xml.Serialization;
using System.IO;/*from w ww.  j av  a2 s  . co m*/
using System.Xml;
using System.Text.RegularExpressions;
using System;

public class Main{
        /// <summary>
        /// Adds the child.   
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        /// <remarks></remarks>
      public static XmlElement AddChild(XmlNode parent, string name)
      {
         XmlDocument document = (parent is XmlDocument) ? (XmlDocument) parent : parent.OwnerDocument;
         XmlElement node = document.CreateElement(name);
         parent.AppendChild(node);
         return node;
      }
        /// <summary>
        /// Adds the child.   
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="name">The name.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        /// <remarks></remarks>
      public static XmlElement AddChild(XmlNode parent, string name, string value)
      {
         if (value == null) return null;

         XmlElement child = AddChild(parent, name);
         child.InnerText = value;
         parent.AppendChild(child);
         return child;
      }
}

Related Tutorials