using System.Xml; XmlDocument xmlDoc = new XmlDocument(); XmlElement newElement = xmlDoc.CreateElement("person");
newElement.SetAttribute("age", "25"); newElement.SetAttribute("gender", "male");Here, we use the SetAttribute method to add attributes to the "person" element we created earlier. We add two attributes, "age" and "gender", with values of "25" and "male", respectively. Package library: System.Xml in the .NET Framework Class Library.