XmlArrayItemAttribute.Form Property

Definition

Gets or sets a value that indicates whether the name of the generated XML element is qualified.

public System.Xml.Schema.XmlSchemaForm Form { get; set; }

Property Value

One of the XmlSchemaForm values. The default is XmlSchemaForm.None.

Exceptions

The Form property is set to XmlSchemaForm.Unqualified and a Namespace value is specified.

Examples

The following example sets the Form property for the Vehicle class to XmlSchemaForm.Unqualified, and the Form property for the Car class to 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;
}

Remarks

The Form property determines whether an XML element name is qualified, based on the World Wide Web Consortium specification Namespaces in XML.

If the Namespace property is set to any value, attempting to set the Form property to XmlSchemaForm.Unqualified throws an exception.

The default value, XmlSchemaForm.None, instructs the XmlSerializer to check the schema for the XML document to determine whether the namespace is qualified. For elements, the XmlSerializer checks the value of the schema-element attribute elementFormDefault. For attributes, it checks the value of the schema-element attribute attributeFormDefault. For example, the following XML Schema indicates that the Name element is qualified, while the Number element is unqualified.

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

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0