要素に属性を追加したい。そして、新しく追加された属性が要素の最初の属性になることを望みます。を使用しましたAddFirst()
が、エラーが発生しました。"An attribute cannot be added to content."
理由がわかりません。
以下は私のコードです。
XElement xmlTree = new XElement("Root",
new XAttribute("Att1", "content1"),
new XAttribute("Att2", "content2")
);
xmlTree.AddFirst(new XAttribute("test", "testAttr"));
要素の最初の属性として属性を追加できる他の方法はありますか?