CSharp examples for System.Xml:XML Attribute
Set XmlNode Attribute
// This is free software licensed under the NUnit license. You may using System.Xml; using System.Collections.Generic; using System;/*from w w w . ja va2 s. c o m*/ public class Main{ public static void SetAttribute(XmlNode node, string name, object value) { bool attrAdded = false; XmlAttribute attr = node.Attributes[name]; if (attr == null) { attr = node.OwnerDocument.CreateAttribute(name); node.Attributes.Append(attr); attrAdded = true; } string valString = value.ToString(); if (attrAdded || attr.Value != valString) attr.Value = valString; } }