Question

I have an XML class inside a .NET 3.5 project which is the top level of the XML file to be generated. I want the element it creates to have a different name called "PersonalAddresses" instead of "Addresses". I get an error when I try to add an XmlElement attribute to the class to set the name of the element it generates. The TypeName of the XmlType attribute doesn't change the name of the generated element. How can I change the generated element name for the class to "PersonalAddresses"?

[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class Addresses
{  class code ... }
Was it helpful?

Solution

I found the answer. I just needed to add an XmlRoot attribute to the class to change the name.

[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)] 
[System.Xml.Serialization.XmlRootAttribute("PersonalAddresses")] 
public partial class Addresses 
{  class code ... } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top