5

I have an XElement object which has a number of attributes and I simply want to add another attribute to the element.

How do I do this?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Matt W
  • 11,753
  • 25
  • 118
  • 215

2 Answers2

13
xElement.Add(new XAttribute("Foo", "Bar"));
Robin Day
  • 100,552
  • 23
  • 116
  • 167
4

To create an element with an attribute use:
var xmlTest = new XElement("XmlElementName", new XAttribute("XmlAttributeName", "AttributeValue"));

Alexander
  • 51
  • 5