February 2012
M T W T F S S
« Apr    
 12345
6789101112
13141516171819
20212223242526
272829  

What elementFormDefault means in XML schema?

The elementFormDefault can be qualified or unqualified, unqualified is the default.
"qualified" means that all the local elements(such as shipTo below) must be qualified, either through specified namespace or default namespace.
Example:
po.xsd as:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:po="http://www.example.com/PO1"
        targetNamespace="http://www.example.com/PO1"
        elementFormDefault="qualified"
        attributeFormDefault="qualified">
  <element name="purchaseOrder" type="po:PurchaseOrderType"/>
  <complexType name="PurchaseOrderType">
    <sequence>
      <element name="shipTo"    type="string"/>
    </sequence>
  </complexType>
</schema> 


Corresponding xml can be:

<?xml version="1.0"?>
<prx:purchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/P01 po2.xsd"
xmlns:prx="http://www.example.com/PO1">
   <prx:shipTo >
  </prx:shipTo>
</prx:purchaseOrder> 

OR

<?xml version="1.0"?>
<purchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/P01 po2.xsd"
xmlns="http://www.example.com/PO1">
   <shipTo >
  </shipTo>
</purchaseOrder> 

"unqualified" means that all the local elements mustn’t be qualified, or to say, must have no namespace.

po.xsd as:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
        xmlns:po="http://www.example.com/PO1"
        targetNamespace="http://www.example.com/PO1"
        elementFormDefault="unqualified"
        attributeFormDefault="unqualified">
  <element name="purchaseOrder" type="po:PurchaseOrderType"/>
  <complexType name="PurchaseOrderType">
    <sequence>
      <element name="shipTo"    type="string"/>
    </sequence>
  </complexType>
</schema> 

Corresponding xml can be:

<?xml version="1.0"?>
<purchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/P01 po.xsd"
xmlns="http://www.example.com/PO1">
   <shipTo xmlns="">
  </shipTo>
</purchaseOrder> 

OR

<?xml version="1.0"?>
<prx:purchaseOrder xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/P01 po.xsd"
xmlns:prx="http://www.example.com/PO1">
   <shipTo>
  </shipTo>
</prx:purchaseOrder>

You can test the above examples in the XML-editor, such as JDeveloper, validating the grammar automatically.

Also, the references below can be useful if you want the further understanding.

And Recently, My colleague Corey clarify this concept too in another blog, whose URL is elementFormDefault attribute, attributeFormDefault attribute and form attribute in XML Schema , also referencing to the above documents:) 

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>