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 - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
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
-
-
-
-
-
-
(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)
-