本篇内容主要讲解“LINQ怎么删除XML节点”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“LINQ怎么删除XML节点”吧!
LINQ删除特定的XML节点的C#代码:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml; using System.Xml.Linq; namespace ConsoleApplication_XML { class Program { static void Main(string[] args) { XElement file = XElement.Load(@"../../Info.xml"); XElement temp = null; IEnumerable query = from elem in file.Element( "applicationPools").Elements("add") where (string)elem.Attribute("name") == "chenjiangsite" select elem; foreach (var e in query) { temp = e; } temp.Remove(); Console.WriteLine(file); } } }
LINQ删除特定的XML节点之XML代码:
﹤IIS7Info﹥ ﹤applicationPools﹥ ﹤add name="DefaultAppPool" /﹥ ﹤add name="Classic .NET AppPool" managedPipelineMode="Classic" /﹥ ﹤add name="domainManager"﹥ ﹤processModel identityType="LocalSystem" /﹥ ﹤/add﹥ ﹤add name="OCSPISAPIAppPool" managedPipelineMode="Classic"﹥ ﹤processModel idleTimeout="00:00:00" /﹥ ﹤recycling﹥ ﹤periodicRestart requests="0" time="00:00:00" /﹥ ﹤/recycling﹥ ﹤/add﹥ ﹤applicationPoolDefaults﹥ ﹤processModel identityType="NetworkService" /﹥ ﹤/applicationPoolDefaults﹥ ﹤/applicationPools﹥ ﹤/IIS7Info﹥
请按任意键继续. . .把file保存就OK了
到此,相信大家对“LINQ怎么删除XML节点”有了更深的了解,不妨来实际操作一番吧!这里是编程网网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!