Mono Class Library: System.Xml Namespace

System.Xml.XmlAttribute Class

An Xml node that is an element attribute. [Edit]

See Also: XmlAttribute Members

System.Object
     System.Xml.XmlNode
          System.Xml.XmlAttribute

public class XmlAttribute : XmlNode, IHasXmlChildNode

Remarks

Attributes are contained in the XmlNode.Attributes property of element nodes. In the Xml below, "attribute" is an attribute of the "example" element.

xml Example
<example attribute="value"/>

The following example shows how an attribute is programmatically added into an Xml document.

C# Example
using System;
using System.Xml;
class MainClass {
       public static void Main(string[] args) {
               Console.WriteLine("Hello World!");
               DomDemo();
       }
       public static void DomDemo() {
               XmlDocument doc=new XmlDocument();
               doc.LoadXml("<root />");
               XmlAttribute a=doc.CreateAttribute("Foo");
               a.Value="Bar";
               doc.DocumentElement.Attributes.Append(a);

               Console.Out.WriteLine(doc.OuterXml);
       }
}
[Edit]

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0