語言

XmlArrayItemAttribute.Form 屬性

定義

取得或設定一個值,指示產生的 XML 元素名稱是否被限定。

public:
 property System::Xml::Schema::XmlSchemaForm Form { System::Xml::Schema::XmlSchemaForm get(); void set(System::Xml::Schema::XmlSchemaForm value); };
public System.Xml.Schema.XmlSchemaForm Form { get; set; }
member this.Form : System.Xml.Schema.XmlSchemaForm with get, set
Public Property Form As XmlSchemaForm

屬性值

這是其中一項 XmlSchemaForm 價值。 預設值為 XmlSchemaForm.None。

例外狀況

Form屬性被設定為 ,XmlSchemaForm.Unqualified並指定一個Namespace值。

範例

以下範例將類別的性質設定為 Form,並將Vehicle類別的XmlSchemaForm.Unqualified性質Form設Car為 XmlSchemaForm.Qualified。

public class Transportation
{
   [XmlArray("Vehicles")]
   // Specifies the Form property value.
   [XmlArrayItem(typeof(Vehicle),
   Form = XmlSchemaForm.Unqualified),
   XmlArrayItem(typeof(Car),
   Form = XmlSchemaForm.Qualified)]
   public Vehicle[] MyVehicles;
}

public class Vehicle
{
   public string id;
}

public class Car:Vehicle
{
   public string Maker;
}
Public Class Transportation
    ' Specify the Form property value.
    <XmlArray("Vehicles"), _
     XmlArrayItem(GetType(Vehicle), Form := XmlSchemaForm.Unqualified), _
     XmlArrayItem(GetType(Car), Form := XmlSchemaForm.Qualified)> _
    Public MyVehicles() As Vehicle
End Class

Public Class Vehicle
    Public id As String
End Class

Public Class Car
    Inherits Vehicle
    Public Maker As String
End Class

備註

此 Form 屬性決定 XML 元素名稱是否符合資格,依據萬維網聯盟(WWI Consortium)在 XML 中的命名空間規範。

如果屬性 Namespace 設定為任意值,嘗試將屬性 Form 設為 會 XmlSchemaForm.Unqualified 拋出例外。

預設值 XmlSchemaForm.None指示 檢查 XmlSerializer XML 文件的結構,以判斷命名空間是否符合資格。 對於元素,會 XmlSerializer 檢查結構元素屬性 elementFormDefault的值。 對於屬性,它檢查結構元素屬性 attributeFormDefault的值。 例如,以下 XML 架構表示該 Name 元素是限定的,而 Number 該元素是未限定的。

<schema elementFormDefault="qualified"
attributeFormDefault="unqualified">
   <element name="Name"/>
   <attribute name="Number"/>
</schema>

適用於