Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlElementAttribute Constructor (String^)

 

Initializes a new instance of the XmlElementAttribute class and specifies the name of the XML element.

Namespace:   System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)

public:
XmlElementAttribute(
	String^ elementName
)

Parameters

elementName
Type: System::String^

The XML element name of the serialized member.

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.

The following example shows a simple class that contains a single field named Vehicles. The example applies the XmlElementAttribute to the field and includes the elementName parameter, thereby instructing the XmlSerializer to generate XML elements named "Cars" rather than "Vehicles".

public ref class Transportation
{
public:

   [XmlElement("Cars")]
   String^ Vehicles;
};

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2017 Microsoft