Welcome!

XML Authors: Jayaram Krishnaswamy, CJ Fearnley, David Dodd, Tad Anderson, Derek Singleton

Related Topics: XML, SOA & WOA

XML: Article

The Specific ElementFormDefault Schema Attribute

The need for a schema definition language

Here is my 'five-minute XML' series where by I give you scheduled byte size guides.

Today's issue is good for those people who happen to be starting out with XML.

In "XML Schema - Overview" (5 Minute XML #7), I reported the need for a schema definition language. I defined principle syntax for the purpose of indicating the namespace from the schema document and W3C URI (for referencing components and attributes not defined from the targetNamespace).

In conclusion I referred to the following schema attribute: <xs:schema elementFormDefault="qualified" ...>.

Here, I am hoping to explain precisely why and how this attribute is used and additionally precisely what influences it brings to bear.

Put simply an XML schema is seen as a group of rules or specification if you like, that the programmer would likely make use of to spell out the structure of an XML document. One example is with a database schema will describe the data which can be within a database (table structure, data types, etc.) An XML Schema is a lot the same for an XML document, it is effectively a rule set.

A schema itself might be contains components from a variety of schemas each in its own namespace. A schema developer will have to make a decision whether or not to uncover or possibly conceal these namespaces to the instance document. The elementFormDefault schema attribute allows them to do just this.

Setting elementFormDefault="unqualified" (the default) will hide (or localise) the namespaces, while setting it to "qualified" definitely will expose the namespaces outlined in the schema to the instance document.

Such as the schema below describes a car which sources components through three or more other schemas. The chassis, wheels and interior are generally resulting from individual makers.

Car.xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="*.w3.org/2001/XMLSchema"
targetNamespace="*.car.org"
xmlns="*.car.org"
xmlns:ford="*.ford.com"
xmlns:toyota="*.toyota.com"
xmlns:audi="*.audi.com"
elementFormDefault="unqualified">
<xsd:import namespace="*.ford.com"
schemaLocation="Ford.xsd"/>
<xsd:import namespace="*.toyota.com"
schemaLocation="Toyota.xsd"/>
<xsd:import namespace="*.audi.com"
schemaLocation="Audi.xsd"/>
<xsd:element name="camera">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="chassis" type="Ford:chassis"/>
<xsd:element name="wheels" type="Toyota:wheels"/>
<xsd:element name="interior" type="Audi:interior"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

Take note the import elements. These accept entry to elements via the diverse manufacturers. Word moreover that the schema attribute elementFormDefault will be set to unqualified. This process covers the many different manufacturers' namespaces from virtually any instance document. Such an instance record may possibly look and feel something like this:

Car.xml
<?xml version="1.0"?>
<my:car xmlns:my="http://www.car.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.car.org Car.xsd">
<chassis>
<description>
Ford F-Series F-150 Regular Cab 2WD
</description>
</chassis>
<wheels alloys="true">
<tyres>Pirelli P3000</tyres>
</wheels>
<interior>
<seatCoverMaterial>leather</seatCoverMaterial>
</interior>
</my:camera>

Only the car root element namespace qualifier is subjected in the instance record, above. The various car brands providing the actual numerous components are at this point concealed or ‘localized' to the schema definition. The instance file doesn't worry itself with where the components are usually taken from. Just that they are accessible.

If, on the other hand, elementFormDefault was indeed set to qualified we would probably have a different story...

These will probably be introduced in another 5 Minute XML article.

A large cornucopia of info is available on the subject of XML for folks who would choose to understand more. For the definitive guide, visit www.W3.org.

Hopefully the above mentioned is beneficial to somebody out there. Much more information will be coming very soon.

More Stories By Tony Gupta

Tony Gupta has worked in the world of IT for almost 20 years now with a special emphasis on XML and web standards technologies since 1994 when XML started to take off. In his personal life he enjoys motor racing and prestige cars. He is also a part-time property developer and has a real passion for renovating old barns.