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

XML Tutorial
1. Introduction
2. Namespace
3. XML Schema
4. XPath
5. XSLT stylesheet
Java
XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
XML Tutorial » XML Schema » attributeFormDefault 
3. 85. 1. Set attributeFormDefault to qualified
<xsd:schema
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  targetNamespace="http://www.java2java.com/namespaces/employee"
  xmlns="http://www.java2java.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.java2java.com/namespaces/employee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.java2java.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.java2java.com/namespaces/employee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.java2java.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
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.