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

Change element and attribute values - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

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