Delete an inner node but not the value in xml with XDocument library in C# .NET

后端 未结 2 580
Happy的楠姐
Happy的楠姐 2021-01-22 23:14

I have the following XML file:



  
    

Add<

2条回答
  •  心在旅途
    2021-01-23 00:09

    Use ReplaceWith, e.g.

    XDocument doc = XDocument.Load("file.xml");
    XElement span = doc.Descendants("p").First().Elements("span").FirstOrDefault(s => (string)s.Attribute("class") == "screenitems");
    if (span != null) 
    {
      span.ReplaceWith(span.Nodes());
    }
    

提交回复
热议问题