delete element from xml using LINQ

前端 未结 1 551
臣服心动
臣服心动 2021-01-06 02:31

I\'ve a xml file like:


   
      mushfiq.com
      mee.con
               


        
相关标签:
1条回答
  • 2021-01-06 03:06

    EDIT: Okay, with further editing, it's clearer what you want to do, and as it happens it's significantly easier than you're making it, thanks to the Remove extension method on IEnumerable<T> where T : XNode:

    string target = txt.Text.Trim();
    doc.Descendants("start")
       .Elements("site")
       .Where(x => x.Value == target)
       .Remove();
    

    That's all you need.

    0 讨论(0)
提交回复
热议问题