Form Attribute Binding Support 

The .NET Framework provides binding support for the form attribute.

The Xsd.exe tool equates the form XML attribute with the Form property of the XmlAttribute or XmlElement attributes, although the .NET Framework's XML serialization code recognizes a different default value, qualified, for elements.


The XML Schema requires that all elements and attributes that are globally declared (as children of the <schema> element) appear namespace-qualified in an instance document. For elements and attributes declared locally (within a <complexType> definition), namespace qualification is optional.

To specify whether to namespace-qualify a particular local element or attribute, the form attribute is added to a local <element> or <attribute> declaration. The possible values are qualified and unqualified.

The form attribute's default value is inherited from either the elementFormDefault or the attributeFormDefault attribute of the root <schema> element. For both of those attributes, the default value is unqualified.

The .NET Framework does not have a way of specifying form on a global or schema-wide level within a class definition. Instead, when generating an XML Schema document from a set of classes, Xsd.exe always produces an XML schema that has the following characteristics:

  • Does not specify attributeFormDefault, reverting to the default unqualified.

  • Specifies elementFormDefault="qualified", effectively using a different default value than does the XML Schema.

Xsd.exe responds to alternate values for the attributeFormDefault="qualified" and elementFormDefault="unqualified" default values by setting form on a per-field basis. (For more details, see attributeFormDefault Attribute and elementFormDefault Attribute.)

Given these constraints, Xsd.exe generates source code from the form attribute as shown in the following table.

form attribute



<attribute> element

The XmlAttribute attribute declaration is passed a Form=XmlSchemaForm.Qualified parameter.

The XmlAttribute attribute declaration for the <attribute> field is passed no form parameter.

<element> element

No XmlElement attribute is applied, unless to pass an unrelated parameter.

The XmlElement attribute declaration for the <element> field is passed a parameter, Form=XmlSchemaForm.Unqualified.

The parameter passed to the XmlAttribute or XmlElement declaration sets the Form property, the possible values for which come from the XmlSchemaForm enumeration:

  • XmlSchemaForm.Qualified

  • XmlSchemaForm.Unqualified

  • XmlSchemaForm.None: the default

Form is specified only in the source code if it is set to the non-default value in the original XML Schema document, according to the .NET Framework defaults as opposed to the XML Schema defaults. Because the form attribute overrides the attributeFormDefault and elementFormDefault attributes, a schema that sets form to the non-default at the <schema> level and then sets it to the default at the <attribute> or <element> level produces source that does not specify form. In terms of conforming instance documents, the meaning is still the same.


Input XML Schema document:

<xsd:schema xmlns:xsd="" 
            xmlns="" targetNamespace="" elementFormDefault="qualified">
  <xsd:element name="ComplexInstance" type="MyComplexType"/>
  <xsd:complexType name="MyComplexType">
      <xsd:element name="elementQ" type="xsd:decimal" form="qualified" />
      <xsd:element name="elementU" type="xsd:Date" form="unqualified" />
    <xsd:attribute name="attributeQ" type="xsd:string"  use="required" form="qualified"/>
    <xsd:attribute name="attributeU" type="xsd:boolean" use="required" form="unqualified"/>

C# class generated from the preceding XML Schema document:

[System.Xml.Serialization.XmlRootAttribute("ComplexInstance", Namespace="", IsNullable=false)]
 public class MyComplexType {
     public System.Decimal elementQ;
    public string elementU;
    public string attributeQ;
    public bool attributeU;

XML Schema document generated from an assembly compiled from the preceding C# source:

<xs:schema xmlns:tns="" elementFormDefault="qualified" targetNamespace="" xmlns:xs="">
  <xs:element name="ComplexInstance" type="tns:MyComplexType" />
  <xs:complexType name="MyComplexType">
      <xs:element minOccurs="1" maxOccurs="1" name="elementQ" type="xs:decimal" />
      <xs:element minOccurs="0" maxOccurs="1" form="unqualified" name="elementU" type="xs:string" />
    <xs:attribute form="qualified" name="attributeQ" type="xs:string" />
    <xs:attribute name="attributeU" type="xs:boolean" use="required" />

Possible containing elements: <attribute>, <element>

See Also