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 - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
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
-
-
-
-
(Locked)
Get an element from XML2m 33s
-
(Locked)
Get an attribute from XML1m 25s
-
(Locked)
Get nodes when using schema namespace3m 32s
-
(Locked)
Get single or multiple elements2m 27s
-
(Locked)
Get child element1m 12s
-
(Locked)
Get child elements1m 58s
-
(Locked)
Use Descendants() to recurse child elements52s
-
(Locked)
Get attributes51s
-
(Locked)
Read element and attribute values1m 32s
-
(Locked)
Change element and attribute values1m 36s
-
(Locked)
Use SetElementValue to add, remove, and modify child elements1m 37s
-
(Locked)
Use SetValue to set with non-string data1m 4s
-
(Locked)
-
-
-