XmlDocument doc = new XmlDocument();
doc.LoadXml("<book><title>War & Peace</title></book>");
//doc.LoadXml("<book Cost=\"456\"><title>War & Peace</title></book>");
XmlElement root = doc.DocumentElement;
XmlAttribute att = doc.CreateAttribute("Cost");
att.InnerXml = "123 €";
root.Attributes.Append(att);
//will properly set the value of Cost attribute to 123
// <book Cost="123 €"><title>War & Peace</title></book>
// and will overwrite already existing attribute, if any
No comments:
Post a Comment