SCDJWS Study Guide: XML Schema


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

An XML Schema Example

An XML Schema Example

The following is the XML schema that defines the shipOrder:

<xsd:schema
  xmlns:xsd="http://www.w3.org/1999
  /XMLSchema">
<xsd:element name="shipOrder"
type="order"/>
<xsd:complexType
name="order">
<xsd:element name="shipTo" 
  type="shipAddress"/>
<xsd:element name="items" 
  type="cdItems"/>
</xsd:complexType>
<xsd:complexType name="shipAddress">
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="street" type="xsd:string"/>
<xsd:element name="address" type="xsd:string"/>
<xsd:element name="country" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="cdItems">
<xsd:element name="item" type="cdItem"/>
</xsd:complexType>
<xsd:complexType name="cdItem">
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="quantity" 
type="xsd:positiveInteger"/>
<xsd:element name="price" type="xsd:decimal"/>
</xsd:complexType>
</xsd:schema>

The XML schema above defines the element <shipOrder> to be of the type order.

The order is a complex type element consisting of the elements <shipTo> and <items>.

The <shipTo> element is of the type shipAddress - a complex type element consisting of the elements <name>, <street>, <address>, and <country>.

The <items> element is of the type cdItems - a complex type element consisting of <item> elements.

The <item> element is of the type cdItem - a complex type element consisting of <title>, <quantity>, and <price> elements.

The <title> element is a normal element of the type string.



An XML Shipping Order Example

The following is an XML document defined by the above XML schema:

<?xml version="1.0"?>
<shipOrder>
<shipTo>
<name>Tove Svendson</name>
<street>Ragnhildvei
2</street>
<address>4000 Stavanger</address>
<country>Norway</country>
</shipTo>
<items>
<item>
<title>Empire
Burlesque</title>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your
heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</items>
</shipOrder>

The XML document consists of a root element <shipOrder>, with two child elements <shipTo> and <items>.

The <items> element contains <item> elements. An <item> element contains <title>,<quantity>, and <price> elements.



Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |