O'Reilly logo

Microsoft® .NET Compact Framework Kick Start by Ronnie Yates, Erik Rubin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required