How to remove XML node by attribute

后端 未结 2 1464
野趣味
野趣味 2020-12-11 22:05

XML


    
      
      
      

        
相关标签:
2条回答
  • 2020-12-11 22:25

    Your code works OK, the problem is that you're trying to overwrite the file you've read the data from.

    See this answer C# : the close method of Xml.Load(file)

    0 讨论(0)
  • 2020-12-11 22:25

    This should works:

    XDocument xdoc = XDocument.Load(filename);
    xdoc.Element("WorkTable").Element("SpecialDays").Elements("Day")
         .Where(x => (string)x.Attribute("date") == "24.07.2015")
         .Remove();
    xdoc.Save(filename);
    
    0 讨论(0)
提交回复
热议问题