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 值。 預設為 XmlSchemaForm.None

例外狀況

Form 屬性設定為 XmlSchemaForm.Unqualified,並且指定 Namespace 值。

範例

下列範例會將 類別的 Vehicle 屬性設定為 XmlSchemaForm.Unqualified ,並將 Form 類別的 Car 屬性設定為 XmlSchemaForm.QualifiedForm

public ref class Vehicle
{
public:
   String^ id;
};

public ref class Car: public Vehicle
{
public:
   String^ Maker;
};

public ref class Transportation
{
public:

   // Specifies the Form property value.

   [XmlArray("Vehicles")]
   [XmlArrayItem(Vehicle::typeid,
   Form=XmlSchemaForm::Unqualified),
   XmlArrayItem(Car::typeid,
   Form=XmlSchemaForm::Qualified)]
   array<Vehicle^>^MyVehicles;
};
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 中的World Wide Web Consortium 規格命名空間,判斷 XML 專案名稱是否限定。

Namespace如果屬性設定為任何值,則嘗試將 屬性設定 FormXmlSchemaForm.Unqualified 擲回例外狀況。

預設值 XmlSchemaForm.NoneXmlSerializer 指示 檢查 XML 檔的架構,以判斷命名空間是否限定。 針對專案,會 XmlSerializer 檢查 schema-element 屬性 elementFormDefault 的值。 如果是屬性,它會檢查 schema-element 屬性 attributeFormDefault 的值。 例如,下列 XML 架構表示元素 Name 是限定的,而元素 Number 不限定。

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

適用於