Add XML Child - CSharp System.Xml

CSharp examples for System.Xml:XML Child

Description

Add XML Child

Demo Code


using System.Xml.Serialization;
using System.IO;/*from w ww  . j  ava2s .c  o  m*/
using System.Xml;
using System.Text.RegularExpressions;
using System;

public class Main{
        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;
      }
        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