语言

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 中的万维网联盟规范命名空间确定 XML 元素名称是否限定。

Namespace如果该属性设置为任何值,则尝试将属性Form设置为XmlSchemaForm.Unqualified引发异常。

默认值 XmlSchemaForm.None指示 XmlSerializer 检查 XML 文档的架构以确定命名空间是否限定。 对于元素,检查 XmlSerializer schema-element 属性 elementFormDefault的值。 对于属性,它会检查 schema-element 属性 attributeFormDefault的值。 例如,下面的 XML 架构指示 Name 该元素是限定的,而 Number 元素不限定。

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

适用于