Adds an attribute to an XML node. - CSharp System.Xml

CSharp examples for System.Xml:XML Attribute

Description

Adds an attribute to an XML node.

Demo Code


using System.Xml;

public class Main{
        /// <summary>
        /// Adds an attribute to an XML node.
        /// </summary>
        /// <param name="node">The XML node.</param>
        /// <param name="name">The attribute name.</param>
        /// <param name="value">The attribute value.</param>
        public static void AddAttribute(XmlNode node, string name, object value)
        {//w  w w.  j a v  a  2 s .  c  om
            XmlAttribute attr = node.OwnerDocument.CreateAttribute(name);
            attr.Value = value.ToString();
            node.Attributes.Append(attr);
        }
}

Related Tutorials