Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to delete a XML node by LINQ

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to delete XML nodes by LINQ". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "LINQ how to delete XML nodes"!

LINQ removes the C # code for a specific XML node:

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 removes the XML code for a specific XML node:

< 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 >

Please press any key to continue. . . Save the file and OK it.

At this point, I believe you have a deeper understanding of "LINQ how to delete XML nodes". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report