spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / authoring / languages / xml / schemas / chap1 / 4 current pageTo page 2To page 3To page 4
[next]

Professional XML Schemas

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


Example Schema: Delivery Receipt

[The following is a continuation of our series of excerpts from Chapter 1 of the Wrox Press title, Professional XML Schemas - Ed.]

In this example, we'll see how to create a schema for a delivery receipt called DeliveryReceipt.xsd. The schema contains constructs for names, addresses, and delivery items.

The delivery receipt is held within a root element called DeliveryReceipt, which has two attributes, deliveryID and dateReceived. The customer's name and address are then held within an element called Customer. Finally, the delivered items will be held within an Items element.

Here is a sample document marked up according to the DeliveryReceipt.xsd schema called DeliveryReceipt.xml:

<?xml version = "1.0" ?>
<DeliveryReceipt deliveryID = "44215" dateReceived = "2001-04-16" 
  xsi:noNamespaceSchemaLocation = "http://file_Location/DeliveryReceipt.xsd"
  xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">
   <Customer>
      <Name>
         <FirstName>Ray</FirstName>
         <MiddleInitial>G</MiddleInitial>
         <LastName>Bayliss</LastName>
      </Name>
      <Address>
         <AddressLine1>10 Elizabeth Place</AddressLine1>
         <AddressLine2></AddressLine2>
         <Town>Paddington</Town>
         <City>Sydney</City>
         <StateProvinceCounty>NSW</StateProvinceCounty>
         <ZipPostCode>2021</ZipPostCode>
      </Address>
   </Customer>
   <Items>
      <DeliveryItem quantity = "2">
         <Description>Small Boxes</Description>
      </DeliveryItem>
   </Items>
</DeliveryReceipt>

Note how we indicate to a parser that it will be able to find a schema to validate the document using the xsi:noNamespaceSchemaLocation attribute in the root element. We use this because the constructs in the schema do not belong to a namespace. In order to use this attribute, we also need to declare the namespace for the XML Schema for instance documents:

<DeliveryReceipt deliveryID = "44215" dateReceived = "2001-04-16" 
  xsi:noNamespaceSchemaLocation = "http://file_Location/DeliveryReceipt.xsd"
  xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance">

home / authoring / languages / xml / schemas / chap1 / 4 current pageTo page 2To page 3To page 4
[next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

Created: October 30, 2001
Revised: October 30, 2001


URL: http://webreference.com/authoring/languages/xml/schemas/chap1/4/