Requiring All Elements and Attributes Be Qualified : elementFormDefault « XML Schema « XML






Requiring All Elements and Attributes Be Qualified


<?xml version = "1.0" ?> 
<schema xmlns = "http://www.w3.org/2001/XMLSchema"
        targetNamespace = "http://www.java2s.com/employees"
        xmlns:cust = "http://www.java2s.com/employees"
        elementFormDefault = "qualified"
        attributeFormDefault = "qualified">
   
   <element name = "employee" type = "cust:employeeType" />
   
   <complexType name = "employeeType">
      <sequence>
         <element name = "FirstName" type = "string" />
         <element name = "MiddleInitial" type = "string" />
         <element ref = "cust:LastName" />
      </sequence>
      <attribute name = "clubCardMember" type = "boolean" />
      <attribute ref = "cust:employeeID" />
   </complexType>
   
   <element name = "LastName" type = "string" />
   <attribute name = "employeeID" type = "integer" />
   
</schema>

We could qualify each element and attribute individually like so: 
<?xml version = "1.0" ?>
<cust:employee xmlns:cust = "http://www.java2s.com/employees"
               cust:clubCardMember = "true" 
               cust:employeeID = "24427">
   <cust:FirstName>Ray</cust:FirstName>
   <cust:MiddleInitial>G</cust:MiddleInitial>
   <cust:LastName>Bayliss</cust:LastName>
</cust:employee>

But the following would NOT be valid:
<?xml version = "1.0" ?>
<employee xmlns = "http://www.java2s.com/employees"
          clubCardMember = "true" 
          employeeID = "24427">
   <FirstName>first</FirstName>
   <MiddleInitial>middle</MiddleInitial>
   <LastName>last</LastName>
</employee>

 








Related examples in the same category

1.elementFormDefault="unqualified"
2.elementFormDefault = "qualified", attributeFormDefault = "unqualified"
3.attributeGroup for elementFormDefault = "qualified"
4.using local element declarations for the children of the employee element
5.If the schema had a value of unqualified for elementFormDefault it would look like so RussianDoll_eu_au.xml
6.Each element and attribute is declared globally
7.elementFormDefault=unqualified Salami Slice