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.
Get an element from XML - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
Get an element from XML
- [Instructor] XML by its nature represents hierarchical information it's a tree of related elements. In my example, I've got this root element called Collectibles and there's multiple children elements. There's the cards, there's multiple cards all at the same level. And then within the card, there are some other child elements like Slogan and Bidprice. So as I'm working with my XML data I need to figure out how to go from the root element down through this tree to get the information that I want. So let's take a look at an example. I'm starting by loading this BigStar Collectibles with NoSchema. That's what I'm doing here in this region. And then this represents the root element. So what I want to do is go and get one of its children elements. So I'm going to call dot Element. That gets a single element by the name the name I'm supplying is Card and that will get the first matching element. So in my file, that…
Contents
-
-
-
-
Get an element from XML2m 33s
-
Get an attribute from XML1m 25s
-
Get nodes when using schema namespace3m 32s
-
Get single or multiple elements2m 27s
-
Get child element1m 12s
-
Get child elements1m 58s
-
Use Descendants() to recurse child elements52s
-
Get attributes51s
-
Read element and attribute values1m 32s
-
Change element and attribute values1m 36s
-
Use SetElementValue to add, remove, and modify child elements1m 37s
-
Use SetValue to set with non-string data1m 4s
-
-
-
-