XmlElementAttribute.ElementName Property
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);
Property Value
The name of the generated XML element. The default is the member identifier.
Remarks
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.
Example
[Visual Basic, C#, 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++] // This is the class that will be serialized. public __gc class XClass { /* The XML element name will be XName instead of the default ClassName. */ public: [XmlElement(ElementName = S"XName")] String* ClassName; };
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
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
See Also
XmlElementAttribute Class | XmlElementAttribute Members | System.Xml.Serialization Namespace | AttributeName