Get the App
SLTechnology News&Howtos  ›  Development  › 

How to delete a XML node by LINQ

Shulou Source: shulou.com Published: 2022-06-02 08:58:31 11月02日 Update

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!

Tags: Node code content learning practical deeper interested practical practical easy to operate method more friends websites channels Centers query Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL OPPO Reno Redmi Xiaomi