ElementName Property

XmlElementAttribute.ElementName Property


Gets or sets the name of the generated XML element.

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

public string ElementName { get; set; }

Property Value

Type: System.String

The name of the generated XML element. The default is the member identifier.

Specify an ElementName if you want the name of the generated XML element to differ from the member's identifier.

You can set the same ElementName value to more than one class member if the generated XML document uses XML namespaces to distinguish between the identically named members. For details on how to use namespaces and prefixed names in the XML document, see the XmlSerializerNamespaces class.

The following example sets the ElementName property of an XmlElementAttribute to a new value.

// This is the class that will be serialized.
public class XClass
   /* The XML element name will be XName
   instead of the default ClassName. */
   [XmlElement(ElementName = "XName")]
   public string ClassName;

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