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.

Read element and attribute values

Read element and attribute values - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

Read element and attribute values

- Most of the examples we looked at so far in this course at least in this chapter, we've been working with elements. So we're getting the entire element, which consists of the end tag and the start tag and the content that's between those two tags. And this is interesting when you're working with the element and you need to know the structure of the elementary like I do here on this monster element. But most of the time you're going to want to either read the value that's in that element or replace the value or change it. So the way you do that in an element is you use the dot value property. The dot value property is a string and allows you to read or write the value. So when I call eyeElement.value, like I'm doing here I get back the value that's between the start and end tags. Essentially what it does is it removes those tags. And I end up with just a string content. Now this is troublesome when you get to an example like…

Contents