A
Brief Review of XML Schemas
To get an idea of how these
various other schema definition languages might appear for an XML document,
let’s go back to our online grocery store sample XML document from Chapter 4,
“Creating XML Schemas,” which is shown in Listing 6.1.
LISTING 6.1 PurchaseOrder.xml Provides
a Sample XML Document for an Online Grocery
Store Order
<PurchaseOrder Tax=”5.76”
Total=”75.77”>
<ShippingInformation>
<Name>Dillon Larsen</Name> <Address>
<Street>123 Jones
Rd.</Street>
<City>Houston</City>
<State>TX</State>
<Zip>77381</Zip>
</Address>
<Method>USPS</Method>
<DeliveryDate>2001-08-12</DeliveryDate>
</ShippingInformation>
<BillingInformation>
<Name>Madi Larsen</Name> <Address>
<Street>123 Jones
Rd.</Street> <City>Houston</City>
<State>TX</State> <Zip>77381</Zip>
</Address>
<PaymentMethod>Credit
Card</PaymentMethod> <BillingDate>2001-08-09</BillingDate>
</BillingInformation>
<Order SubTotal=”70.01” ItemsSold=”17”>
<Product Name=”Baby
Swiss” Id=”702890” Price=”2.89”
➥ Quantity=”1”/>
<Product Name=”Hard
Salami” Id=”302340” Price=”2.34”
➥ Quantity=”1”/>
<Product Name=”Turkey”
Id=”905800” Price=”5.80”
➥ Quantity=”1”/>
<Product Name=”Caesar
Salad” Id=”991687” Price=”2.38”
➥ Quantity=”2”/>
<Product Name=”Chicken
Strips” Id=”133382” Price=”2.50”
➥ Quantity=”1”/>
<Product Name=”Bread”
Id=”298678” Price=”1.08”
➥ Quantity=”1”/>
<Product Name=”Rolls”
Id=”002399” Price=”2.24”
➥ Quantity=”1”/>
<Product Name=”Cereal”
Id=”066510” Price=”2.18”
➥ Quantity=”1”/>
<Product Name=”Jalapenos” Id=”101005”
Price=”1.97”
➥ Quantity=”1”/>
<Product Name=”Tuna”
Id=”000118” Price=”0.92”
➥ Quantity=”3”/>
<Product Name=”Mayonnaise” Id=”126860”
Price=”1.98”
➥ Quantity=”1”/>
<Product Name=”Top
Sirloin” Id=”290502” Price=”9.97”
➥ Quantity=”2”/>
<Product Name=”Soup”
Id=”001254” Price=”1.33”
➥ Quantity=”1”/>
<Product Name=”Granola
Bar” Id=”026460” Price=”2.14”
➥ Quantity=”2”/>
<Product Name=”Chocolate Milk”
Id=”024620” Price=”1.58”
➥ Quantity=”2”/>
<Product Name=”Spaghetti” Id=”000265”
Price=”1.98”
➥ Quantity=”1”/>
<Product Name=”Laundry
Detergent” Id=”148202” Price=”8.82”
➥ Quantity=”1”/> </Order>
</PurchaseOrder>
As you can see, Listing 6.1
represents a fairly small and simple order that could be placed online. It
contains the information necessary regarding how payment is to be made, how the
order is to be shipped, and what day delivery should be. For comparison
purposes with the other schema formats discussed in the rest of this chapter,
we’ll also include the W3C schema for our sample XML document, as shown in
Listing 6.2.
LISTING 6.2 PurchaseOrder.xsd Contains
a W3C Schema for PurchaseOrder.xml
<xsd:schema
xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>
<xsd:annotation>
<xsd:documentation>
Purchase Order schema for an
online grocery store. </xsd:documentation>
</xsd:annotation>
<xsd:element name=”PurchaseOrder” type=”PurchaseOrderType”/>
<xsd:complexType
name=”PurchaseOrderType”> <xsd:all>
<xsd:element
name=”ShippingInformation” type=”InfoType” ➥ minOccurs=”1”
maxOccurs=”1”/>
<xsd:element
name=”BillingInformation” type=”InfoType” ➥ minOccurs=”1”
maxOccurs=”1”/>
<xsd:element name=”Order”
type=”OrderType” ➥ minOccurs=”1”
maxOccurs=”1”/>
</xsd:all>
<xsd:attribute
name=”Tax”> <xsd:simpleType>
<xsd:restriction
base=”xsd:decimal”> <xsd:fractionDigits value=”2”/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name=”Total”>
<xsd:simpleType>
<xsd:restriction base=”xsd:decimal”>
<xsd:fractionDigits
value=”2”/> </xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
<xsd:group
name=”ShippingInfoGroup”> <xsd:all>
<xsd:element
name=”DeliveryDate” type=”DateType”/> <xsd:element name=”Method”
type=”DeliveryMethodType”/>
</xsd:all>
</xsd:group>
<xsd:group name=”BillingInfoGroup”>
<xsd:all>
<xsd:element
name=”BillingDate” type=”DateType”/> <xsd:element name=”PaymentMethod”
type=”PaymentMethodType”/>
</xsd:all>
</xsd:group>
<xsd:complexType
name=”InfoType”> <xsd:sequence>
<xsd:element name=”Name”
minOccurs=”1” maxOccurs=”1”> <xsd:simpleType>
<xsd:restriction
base=”xsd:string”/> </xsd:simpleType>
</xsd:element>
<xsd:element
name=”Address” type=”AddressType” minOccurs=”1” ➥ maxOccurs=”1”/>
<xsd:choice minOccurs=”1”
maxOccurs=”1”> <xsd:group ref=”BillingInfoGroup”/> <xsd:group
ref=”ShippingInfoGroup”/>
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
<xsd:simpleType
name=”DateType”> <xsd:restriction base=”xsd:date”/>
</xsd:simpleType>
<xsd:simpleType
name=”DeliveryMethodType”> <xsd:restriction base=”xsd:string”>
<xsd:enumeration
value=”USPS”/> <xsd:enumeration value=”UPS”/> <xsd:enumeration
value=”FedEx”/> <xsd:enumeration value=”DHL”/> <xsd:enumeration
value=”Other”/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType
name=”OrderType”> <xsd:all>
<xsd:element
name=”Product” type=”ProductType” ➥ minOccurs=”1”
maxOccurs=”unbounded”/>
</xsd:all>
<xsd:attribute
name=”SubTotal”> <xsd:simpleType>
<xsd:restriction
base=”xsd:decimal”> <xsd:fractionDigits value=”2”/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name=”ItemsSold”
type=”xsd:positiveInteger”/> </xsd:complexType>
<xsd:complexType
name=”ProductType”> <xsd:attribute name=”Name” type=”xsd:string”/>
<xsd:attribute name=”Id”
type=”xsd:positiveInteger”/> <xsd:attribute name=”Price”>
<xsd:simpleType>
<xsd:restriction
base=”xsd:decimal”> <xsd:fractionDigits value=”2”/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute
name=”Quantity” type=”xsd:positiveInteger”/> </xsd:complexType>
</xsd:schema>
For a more detailed
explanation regarding the schema in the preceding listing, refer to Chapter 4.
As you can see from this listing, the XML Schema Definition Language can get
rather complex and very detailed. But what about some of the other schema
formats that have been proposed over time? We’ll take the rest of the chapter
to discuss these alternative schema formats and compare them against the XML
Schema from the preceding listing.
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.