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.

XDocument compared to XElement

XDocument compared to XElement - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

XDocument compared to XElement

- [Narrator] I'd like to talk about the differences between the X element and X document classes. For most of this course, we've been working with the X element and we've been doing that by calling XElement.Load. Now X element represents one of the elements within the XML tree. It could be the root element or it can be any of the children. X document represents the entire XML doc, and that would include things like the XML declaration. If you look on line five, you can see that there is a way to load an X document. It's the same syntax, the only difference is when you call XDocument.Load it returns the next document, where Xelement.Load returns an X element. So let's see what we got here when we dump the X doc and the X element values. So here you see here, X doc, I'm getting a comment at the top of the XML document, and then I'm getting the root element and all of it's children. Whereas if I look at X element, I…

Contents