Gets or sets the name of the generated XML element.
[Visual Basic] Public Property ElementName As String [C#] public string ElementName {get; set;} [C++] public: __property String* get_ElementName(); public: __property void set_ElementName(String*); [JScript] public function get ElementName() : String; public function set ElementName(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.
[Visual Basic, C#] The following example sets the ElementName property of an XmlElementAttribute to a new value.
[Visual Basic] ' 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 ClassName() As String End Class [C#] // 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; }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework - Windows CE .NET
XmlElementAttribute Class | XmlElementAttribute Members | System.Xml.Serialization Namespace | AttributeName