Extensible Schema Definitions (XSD) are used to define the legal building blocks of an XML document. XSD is actually an XML based meta-language used to:
- Define the elements that can appear in an XML Document
- Define attributes that can appear in an XML Document
- Define the child elements and their relationships within an XML Document
All XSD schemas contain a single top level element. Underneath this element is the schema element that contains either simple or complex type elements. Simple elements contain text only information. Complex elements are a grouping element that acts as a container for other elements and attributes. There are four types of complex elements – empty elements, elements that contain other elements, elements that contain only text and elements that contain both other elements and text.
Here is an example of an XSD that defines a schema structure that represents a customer record.
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="prefix" type="xsd:string"/>
<xsd:element name="firstname" type="xsd:string"/>
<xsd:element name="lastname" type="xsd:string"/>
<xsd:element name="suffix" type="xsd:string"/>
<xsd:element name="email" type="xsd:string"/>
<xsd:element name="mail1" type="xsd:string"/>
<xsd:element name="mail2" type="xsd:string"/>
<xsd:element name="mailstate" type="xsd:string"/>
<xsd:element name="mailzip" type="xsd:string"/>
<xsd:element name="entereddate" type="xsd:date"/>
<xsd:element name="customerinfo">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="prefix" minOccurs="0"/>
<xsd:element ref="firstname"/>
<xsd:element ref="lastname"/>
<xsd:element ref="suffix" minOccurs="0"/>
<xsd:element ref="email"/>
<xsd:element ref="mail1"/>
<xsd:element ref="mail2"/>
<xsd:element ref="mailstate"/>
<xsd:element ref="mailzip"/>
<xsd:element ref="entereddate"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
11:19:35 PM
|