Add New XML Node - CSharp System.Xml

CSharp examples for System.Xml:XML Node

Description

Add New XML Node

Demo Code


using System.Text.RegularExpressions;
using System.Xml;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*  w  w w  .  java  2 s.c o m*/

public class Main{
        public static XmlNode AddNewNode(XmlNode fathernode, string name, string content)
        {
            XmlDocument xdoc = fathernode.OwnerDocument;
            XmlNode snode = xdoc.CreateElement(name);
            if (!String.IsNullOrEmpty(content))
            {
                snode.InnerXml = ReplaceInvalidChar(content);
            }
            fathernode.AppendChild(snode);
            return snode;
        }
}

Related Tutorials