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

Rename elements and attributes - .NET Tutorial

From the course: .NET Essentials: LINQ for XML

Start my 1-month free trial

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