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.
Create XML structure - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
Create XML structure
- [Instructor] There are times when you need to generate an XML tree from code. Most of the examples we've seen in this course showed how to query XML data, how to get existing elements and attributes, plus we've seen how to read and write values to an existing tree. Now we'll see how to create our own XML tree. I thought I'd start by creating an instance of an XDocument. So that's what I'm doing on line three. Then I instantiate a comment and add it to the doc. Then I instantiate a card and add that to the doc. And then I'm going to dump out what we have so far. So we see there's the document level comment and there's our empty Card. Now, I'll comment out this line and continue. Then I add a couple of attributes to the card, I add another comment to the card. This time it's in the card, not in the document level. Add a few more elements and then I want to do some children elements. So here I'm instantiating a new…
Contents
-
-
-
-
-
-
(Locked)
Use the DumpFormatted extension method1m 32s
-
(Locked)
XDocument compared to XElement2m 40s
-
(Locked)
Create XML structure3m 18s
-
(Locked)
Rename elements and attributes1m 49s
-
(Locked)
Replace elements and attributes1m 30s
-
(Locked)
Remove element1m 26s
-
(Locked)
Add parent element and move elements2m 14s
-
(Locked)
Challenge: Move attributes and elements1m 9s
-
(Locked)
Solution: Move attributes and elements2m 31s
-
(Locked)
-