From the course: .NET Essentials: LINQ for XML

Unlock the full course today

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

Add parent element and move elements

Add parent element and move elements - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

Add parent element and move elements

- In this example, I'd like to see how we can move elements around in the XML tree. So we're going to start with the elements in one location and we're going to move them to be Children under another element. So here's what we're trying to do. So this is the original data. I have a collectibles root element and there's seven card elements under collectibles. What I'd like to have is collectibles and then cards. Cause eventually in our company, we're going to have different categories of collectibles, not just cards. So I want all the cards to live under this cards element. This is the syntax to do this. So I started off by getting all the existing cards here, starting Windows variable, then I'm going to the root element and I'm adding a new X element called Cards. And then I'm passing in all of the existing card elements, and making those Children. And then I don't need the original element anymore. So this…

Contents