Monday, 21 November 2011

The Actual ElementFormDefault Schema Attribute

Quite simply an XML schema is seen as a group of rules or specification if you'd prefer, which a coder would likely use to describe the structure of an XML document. One example is with a database schema will describe the data that may be found in a database (table structure, data types, etc.) An XML Schema is much the same for an XML document, it is effectively a rule set.

A schema by itself is actually contains components coming from several schemas each in its own namespace. A schema developer needs to choose if they should uncover or maybe hide these namespaces to the instance doc. The elementFormDefault schema attribute allows them to do just this.

Setting elementFormDefault="unqualified" (the default) will hide (or localise) the namespaces, whereas setting it to "qualified" definitely will expose the namespaces explained around the schema to the instance record.

One example is the schema beneath portrays a car which actually sources components coming from two to three other schemas. The chassis, wheels and interior are typically resulting from separate suppliers.

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>

Notice the import elements. These facilitate entry to elements via the diverse manufacturers. Note in addition that the schema attribute elementFormDefault is set to unqualified. This method hides the various manufacturers’ namespaces from any instance doc. This kind of an instance record could possibly look something for instance :

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>

Merely the car root element namespace qualifier is usually totally exposed in the instance record, above. The various car manufacturers supplying the various components are right now hidden or ‘localised’ to the schema definition. The instance record doesn’t worry itself with the place where the components are sourced from. Just that they are obtainable.

If perhaps, on the other hand, elementFormDefault turned out to be set to qualified we would most likely have a different story…

These will definitely be presented in another 5 Minute XML course.

A wealth of facts are available about XML should you would want to uncover more. For the definitive guide, visit www.W3.org.

I hope the above is useful to an individual out there. More article content will be coming shortly.

No comments:

Post a Comment