XmlElementAttribute.ElementName 屬性

定義

取得或設定產生的 XML 項目的名稱。

public:
 property System::String ^ ElementName { System::String ^ get(); void set(System::String ^ value); };
public string ElementName { get; set; }
member this.ElementName : string with get, set
Public Property ElementName As String

屬性值

產生的 XML 項目的名稱。 預設值為成員識別項。

範例

下列範例會將 ElementNameXmlElementAttribute 屬性設定為新的值。

// This is the class that will be serialized.
public ref class XClass
{
public:
   /* The XML element name will be XName
   instead of the default ClassName. */
   [XmlElement(ElementName="XName")]
   String^ ClassName;
};
// 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;
}
' 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

備註

ElementName如果您想要產生之 XML 專案的名稱與成員的識別碼不同,請指定 。

如果產生的 XML 檔使用 XML 命名空間來區分相同具名成員,您可以將相同的 ElementName 值設定為多個類別成員。 如需如何在 XML 檔中使用命名空間和前置名稱的詳細資訊,請參閱 類別 XmlSerializerNamespaces

適用於

另請參閱