Adds a new element as a child of an existing XmlNode and returns it. - CSharp System.Xml

CSharp examples for System.Xml:XML Element

Description

Adds a new element as a child of an existing XmlNode and returns it.

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;//from  w w  w. j  a  v a 2 s  .  com

public class Main{
        /// <summary>
        /// Adds a new element as a child of an existing XmlNode and returns it.
        /// </summary>
        /// <param name="node">The node to which the element should be added.</param>
        /// <param name="name">The element name.</param>
        /// <returns>The newly created child element</returns>
        public static XmlNode AddElement(this XmlNode node, string name)
        {
            XmlNode childNode = node.OwnerDocument.CreateElement(name);
            node.AppendChild(childNode);
            return childNode;
        }
}

Related Tutorials