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