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.
Change element and attribute values - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
Change element and attribute values
- [Narrator] Let's start by looking at how to change the value of an attribute. The value property is a read write string property, so it's easy to get the value and it's easy to set the value. I started with attributes because they're a little easier than working with elements. There are some other considerations you need to take when you're working with elements. Right here, you can see this is the name value pair. Here's the value. Then I assigned this new string value and now you can see that's in the name value pair. And also if I retrieve the value again, I get the modified value. Now with a simple example like this where we have an element, a single element, and I want to get this value, that's easy to do with the dot value. Remember, this is coming back as a string. So if I want to change the value, I will use a string. In this case, the string five. You can see I've changed the value here and…
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)
-
-
-