Creating XmlAttributes

To create an XmlAttribute, the XmlDocument provides the CreateAttribute method. This method creates an XmlAttribute node linked to the current XmlDocument. The value must be set after the XmlAttribute is created (see Listing 11.18).

Listing 11.18.
C#
XmlAttribute newAttribute = XmlDoc.CreateAttribute("att");
newAttribute.Value = "val";

VB
Dim newAttribute As XmlDoc.CreateAttribute("att")
newAttribute.Value = "val"

After creating the attribute, you must add it to an XmlElement. The XmlElement's SetAttributeNode method provides this functionality. The SetAttributeNode takes the newly created XmlAttribute and adds it to the XmlElement's list of attributes. The SetAttributeNode method has an overload that takes two parameters: ...

Get Microsoft® .NET Compact Framework Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.