XmlElementAttribute Constructor (String, Type)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Initializes a new instance of the XmlElementAttribute and specifies the name of the XML element and a derived type for the member to which the XmlElementAttribute is applied. This member type is used when the XmlSerializer serializes the object that contains it.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- elementName
- Type: System.String
The XML element name of the serialized member.
- type
- Type: System.Type
The Type of an object derived from the member's type.
By default, the XmlSerializer uses the member name as the XML element name when serializing a class instance. For example, a field named Vehicle generates an XML element named Vehicle. However, if you need a different element, such as Cars, pass it in the elementName parameter.
Use the type parameter to specify a type that is derived from a base class. For example, suppose a property named MyAnimal returns an Animal object. You want to enhance the object, so you create a new class named Mammal that inherits from the Animal class. To instruct the XmlSerializer to accept the Mammal class when it serializes the MyAnimal property, pass the Type of the Mammal class to the constructor.