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.
Rename elements and attributes - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
Rename elements and attributes
- In this video we'll see how to rename an element or attribute. This is a common task when transforming the contents of one XML file into another. The X element class has a name property. This is a read-write property. So I can find the element by this name. And then I can assign a new name by just changing the value in the name property. Here's the results. The font size is smaller than I'd like in this output window. And that's because I haven't determined how to change the font size when I call 'DumpFormatted' in the link pad. But let's look at the results, anyway. Here's the original value, 'PublishDate'. And here's the modified value, 'ReleaseDate'. You would think it'd be the same for changing an attribute, but it's not. And that's because the name property on X attribute is read-only. Now why that's the case, I don't know. When I try to run code like this it says that it's a read-only property. So…
Contents
-
-
-
-
-
-
(Locked)
Use the DumpFormatted extension method1m 32s
-
(Locked)
XDocument compared to XElement2m 40s
-
(Locked)
Create XML structure3m 18s
-
(Locked)
Rename elements and attributes1m 49s
-
(Locked)
Replace elements and attributes1m 30s
-
(Locked)
Remove element1m 26s
-
(Locked)
Add parent element and move elements2m 14s
-
(Locked)
Challenge: Move attributes and elements1m 9s
-
(Locked)
Solution: Move attributes and elements2m 31s
-
(Locked)
-