Bearbeiten

Freigeben über


XmlAttributeAttribute.Form Property

Definition

Gets or sets a value that indicates whether the XML attribute name generated by the XmlSerializer is qualified.

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

Property Value

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

Examples

The following example applies the XmlAttributeAttribute to two fields contained in a class.

public ref class Vehicle
{
public:

   [XmlAttributeAttribute(Form=XmlSchemaForm::Qualified)]
   String^ Maker;

   [XmlAttributeAttribute(Form=XmlSchemaForm::Unqualified)]
   String^ ModelID;
};
public class Vehicle
{
   [XmlAttribute(Form = XmlSchemaForm.Qualified)]
   public string Maker;

   [XmlAttribute(Form = XmlSchemaForm.Unqualified)]
   public string ModelID;
}
Public Class Vehicle
    <XmlAttribute(Form := XmlSchemaForm.Qualified)> _
    Public Maker As String    

    <XmlAttribute(Form := XmlSchemaForm.Unqualified)> _
    Public ModelID As String
End Class

Remarks

The Form property determines whether an XML element is qualified or unqualified. The Form property conforms to the 1999 http://www.w3.org 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 setting, XmlSchemaForm.None, instructs the XmlSerializer to check the schema for the XML document to determine whether the namespace is qualified. If the schema does not specify a value for an individual element or attribute, the XmlSerializer uses the elementFormDefault and attributeFormDefault values to determine whether an element or attribute is qualified. The following XML code shows a schema:

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

When the XmlSerializer reads the schema, the Form value for both the Name and Number is XmlSchemaForm.None, but the Name element is qualified, while the Number element is unqualified.

Applies to