Typ
is element name, not an attribute. If you meant to add new <DUT>
element after existing <DUT>
under the second <Bench>
, this slight change to the code you've tried should work :
var xElement = xmlDoc.Element("Assembly")
.Elements("Bench")
.FirstOrDefault(item => item.Element("Typ").Value == "P2");
xElement.AddAfterSelf(new XElement("DUT"));