Home arrow XML arrow Page 2 - Designing Your own XML Schema: Learn the Essentials

Designing Your own XML Schema: Learn the Essentials

This is the first article in a series which guides you in designing XML Schemas right from the basics without any hurdles.

Author Info:
By: Jagadish Chaterjee
Rating: 4 stars4 stars4 stars4 stars4 stars / 22
March 06, 2006
  1. · Designing Your own XML Schema: Learn the Essentials
  2. · XML Schema: beginning with the simplest way
  3. · XML Schema: the complex way
  4. · XML Schema: a simple practical example
  5. · XML Schema: a simple practical example continued
  6. · XML Schema: a more practical example

print this article

Designing Your own XML Schema: Learn the Essentials - XML Schema: beginning with the simplest way
(Page 2 of 6 )

To write a schema for any XML document, we could simply follow its structure and define each element as we find it.  Before going into further detail, let us see how we can start an XML Schema.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">

We shall take another look at “elementFormDefault” and “attributeFormDefault” later.  The above states that we are about to start our own schema design, which conforms to the rules and regulations available at http://www.w3.org/2001/XMLSchema (in fact it is an “XML namespace”). “xs” is the preferred prefix, which is mainly used to point to that “namespace” for declarations, definitions or several available structures.

Let us now design a somewhat realistic example.  The following XML Schema defines an element, “Organization,” to be used in our markup.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema 
elementFormDefault="qualified" attributeFormDefault=
      <xs:element name="Organization" type="xs:string" />        

Note that I saved the above in a file named “Sample1.xsd” (every XML Schema is generally stored with an extension “xsd”).  Within the above schema, “Organization” is the element name and “string” is its data type.  The following are the quite common data types used in defining XML Schemas:

  • xs:string
  • xs:decimal
  • xs:integer
  • xs:boolean
  • xs:date
  • xs:time

Now, let us see the XML document which conforms to the above defined schema.

<?xml version="1.0" encoding="UTF-8"?>
<Organization xmlns:xsi="http://www.w3.org/2001/XMLSchema-
companies Ltd.

Now, you can observe that you started with your own “Organization” element, which is exactly what you defined in the schema above.  You should also observe that I included my XSD document (schema), to follow my schema rules and regulations for proper validation.

blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials