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

Create XML structure - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

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