Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlArrayItemAttribute.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 */
public String get_ElementName ()

/** @property */
public void set_ElementName (String value)

public function get ElementName () : String

public function set ElementName (value : String)

Property Value

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 identically named members. For details about how to use namespaces and prefixed names in the XML document, see the XmlSerializerNamespaces class.

The following example sets the ElementName property for the Vehicle and Car class--thereby changing the names of XML elements that the XmlSerializer generates for those classes.

public class Transportation
{  
   [XmlArray("Vehicles")]
   /* Specifies acceptable types and the ElementName generated 
      for each object type. */
   [XmlArrayItem(typeof(Vehicle), ElementName = "Transport"), 
   XmlArrayItem(typeof(Car), ElementName = "Automobile")]
   public Vehicle[] MyVehicles;
}

// By default, this class results in XML elements named "Vehicle". 
public class Vehicle
{
   public string id;
}

// By default, this class results in XML elements named "Car". 
public class Car:Vehicle
{
   public string Maker;
}


public class Transportation
{
    /** @attribute XmlArray("Vehicles")
     */
    /* Specifies acceptable types and the ElementName generated 
       for each object type. 
    */
    /** @attribute XmlArrayItem(Vehicle.class, ElementName = "Transport")
        @attribute XmlArrayItem(Car.class, ElementName = "Automobile")
     */
    public Vehicle myVehicles[];
} //Transportation

// By default, this class results in XML elements named "Vehicle". 
public class Vehicle
{
    public String id;
} //Vehicle

// By default, this class results in XML elements named "Car". 
public class Car extends Vehicle
{
    public String maker;
} //Car

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.