From the course: .NET Essentials: LINQ for XML

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Remove element

Remove element - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

Remove element

- In this video, we'll look at how to remove elements from the XML tree. There are several remove methods available. We're looking at "Remove" in this video, but there are others. There's Remove, which removes this node from its parent. There's RemoveAll, there's RemoveAnnotations and RemoveAttributes. We're going to choose this item here. You specify the element that you want and then call ".Remove." So here's the original data with the "Prices" element and its children. And here's the modified file. You can also use a conditional. Here's the conditional, I'm running a query here. I'm looking for elements where the attribute "card-family" is equal to "Robot." So this will return those items. So, let's run this much, so far. Oh, I have to run everything. So there's all the cards, there's seven. And then here are the "Robot"-only cards, there's three. So if I remove the robots, I should only have four items…

Contents