Linq to XML - update/alter the nodes of an XML Document

后端 未结 6 1681
旧巷少年郎
旧巷少年郎 2020-11-29 06:04

I\'ve got 2 Questions:

1. I\'ve sarted working around with Linq to XML and i\'m wondering if it is possible to change an XML document via Linq. I mean, is there some

6条回答
  •  甜味超标
    2020-11-29 06:36

    thank you for your answer. everything works fine.

    just as completition to my questions the code below shows how to modify a single entry:

    string xml = @"";
    StringReader sr = new StringReader(xml);
    XDocument d = XDocument.Load(sr);
    
    
    d.Descendants("record").Where(x => x.Attribute("id").Value == "2").Single().SetAttributeValue("info", "new sample info");
    

提交回复
热议问题