Set attributeFormDefault to qualified : attributeFormDefault « XML Schema « XML Tutorial






<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.java2s.com/namespaces/employee"
  xmlns="http://www.java2s.com/namespaces/employee"
  elementFormDefault="qualified"
  attributeFormDefault="qualified">
  <xsd:element name="employee">
   <xsd:complexType>
    <xsd:sequence>
     <xsd:element name="name" type="xsd:string"/>
     <xsd:element name="email" type="xsd:string"/>
     <xsd:element name="hireDate" type="xsd:string"/>
    </xsd:sequence>
    <xsd:attribute name="dept" type="xsd:string"/>
    <xsd:attribute name="client" type="xsd:string"/>
   </xsd:complexType>
  </xsd:element>
</xsd:schema>

We have set both attributes to qualified; therefore, all elements and attributes in our instance document must be qualified:

<em:employee
  xmlns:em="http://www.java2s.com/namespaces/employee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.java2s.com/namespaces/employee employee.xsd"
  em:dept="programming"
  em:client="Smith and Co">
  <em:name>Joe Smith</em:name>
  <em:email>a@a.com</em:email>
  <em:hireDate>2008-10-29</em:hireDate>
</em:employee>

If we set elementFormDefault to qualified and omit attributeFormDefault (its default value is unqualified), 
we could use the following document instance:

<em:employee
  xmlns:em="http://www.java2s.com/namespaces/employee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.java2s.com/namespaces/employee employee.xsd"
  dept="programming"
  client="Smith and Co">
  <em:name>Joe Smith</em:name>
  <em:email>a@a.com</em:email>
  <em:hireDate>2008-10-29</em:hireDate>
</em:employee>








3.85.attributeFormDefault
3.85.1.Set attributeFormDefault to qualified
3.85.2.Define prefixes in the schema for both our target namespace and for the W3C XML Schema namespace
3.85.3.Use the target namespace as the default namespace of the schema document
3.85.4.Use prefixes on the components you are defining and use the W3C XML Schema vocabulary without prefixes