From the course: .NET Essentials: LINQ for XML
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Remove element - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
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
-
-
-
-
-
-
Use the DumpFormatted extension method1m 32s
-
XDocument compared to XElement2m 40s
-
Create XML structure3m 18s
-
Rename elements and attributes1m 49s
-
Replace elements and attributes1m 30s
-
Remove element1m 26s
-
Add parent element and move elements2m 14s
-
Challenge: Move attributes and elements1m 9s
-
Solution: Move attributes and elements2m 31s
-
-