From the course: Complete Guide to .NET LINQ: Querying Collections, Databases, and Markup

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Read values from elements and attributes

Read values from elements and attributes

- [Instructor] Up to this point, especially in this chapter, we've been working mostly with the XML elements, which means we've been accessing the entire element. So let's look at this code here. I'm drilling down from the root element to the I count element. In this other example, I'll line above it, I'm getting the monster element, and when I dump out the contents, you can see that I'm getting the entire element, which includes the start tag and the end tag and the content between. This is useful if you're interested in the structure of the element like I'm getting here. I'm interested in knowing the sub elements, but in this case, I just wanted the I count value. In most cases, I won't need the entire element. I'll just want to read or modify or replace this value that's inside the owner. The simplest way to read it is to use the .value property. This property returns a string that represents the content between the start and end tags, effectively stripping away the tags and…

Contents