public static void SetAttributeValue(this XmlElement xmlElement, string attributeName, string value) { XmlAttribute attr = xmlElement.Attributes[attributeName]; if (attr == null) { AddAttribute(xmlElement, attributeName, value); } else { attr.Value = value; } }