I want to add an attribute into an element. And I wish the new added attribute to be the first attribute in the element. I used the AddFirst()
, I got an error : "An attribute cannot be added to content."
I don't know why?
the following is my codes.
XElement xmlTree = new XElement("Root",
new XAttribute("Att1", "content1"),
new XAttribute("Att2", "content2")
);
xmlTree.AddFirst(new XAttribute("test", "testAttr"));
Any other way allows me to add an attribute as a first attribute in the element?
This will solve your problem. AddFirst can not be use in this case.