Linq to XML Add element to specific sub tree

后端 未结 3 771
南笙
南笙 2021-01-11 17:08

My XML:


 
  
   
                         
           


        
3条回答
  •  死守一世寂寞
    2021-01-11 17:24

    var cust = xDoc.Descendants("Customer")
                   .First(c => c.Attribute("id").Value == "2");
    cust.Element("Accounts").Add(new XElement("Account", new XAttribute("id","3") ));
    

提交回复
热议问题