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 值。

示例

以下示例将FormXmlSchemaForm.Unqualified的属性Vehicle设置为 ,并将Form类的属性Car设置为 XmlSchemaForm.Qualified

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

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

默认值 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>  

适用于