From the course: .NET Essentials: LINQ for XML

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Use SetElementValue to add, remove, and modify child elements

Use SetElementValue to add, remove, and modify child elements - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

Use SetElementValue to add, remove, and modify child elements

- There are methods that can be used to change the value of an element and an attribute. So rather than using the property and changing it you can also use these methods here. There's the set attribute value, the set element value, and set value. In this video, we'll look at set element value. We're looking at the set element value method. It takes two parameters. The name of the element that you want to change and the value for that element. Now this is working with children elements like I have here. I have the monster element and it has three children: antenna, spikes, and eye count. And the purpose of this method, the set element value is to be able to change these children elements. So the first thing I can do is change the value. So if this is a name of an existing child element you will find it and replace the content with this new value. Notice that I'm not using a string here either. I'm using a Boolean variable.…

Contents