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

Get an element from XML - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

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