XML
  Home arrow XML arrow Page 2 - Designing Your own XML Schema: Restriction...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Designing Your own XML Schema: Restrictions and User Defined Types
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2006-03-20

    Table of Contents:
  • Designing Your own XML Schema: Restrictions and User Defined Types
  • Restrictions based on patterns in XML Schema
  • How to define your own simple type (user-defined data type) in XML Schema
  • Understanding the user-defined simple type in XML Schema
  • User-defined Simple Type with enumeration in XML Schema
  • Understanding the simple type with enumeration in XML Schema
  • User-defined Complex Type in XML Schema

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Designing Your own XML Schema: Restrictions and User Defined Types - Restrictions based on patterns in XML Schema


    (Page 2 of 7 )

    Let us consider that we would like to have an employee ID to be provided with only five digits, in the form of a string.  If it is in the form of a string, it would accept any character.  I wanted to restrict it to only digits.  Another good example along the same lines would be a zip code.

    In these situations, you can use “patterns” in XML Schema.  Even though I present a simple example of this, I suggest you refer to http://www.w3c.org/ for further in-depth information on “patterns.”  It is just beyond the scope of this article to concentrate so deeply on patterns.

    Let us look at the following complete schema before I give a complete explanation:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/
    XMLSchema
    " elementFormDefault="qualified" 
    attributeFormDefault="unqualified">
      <xs:element name="Employees">
        <xs:annotation>
          <xs:documentation>Contains All Employee information</xs:documentation>
        </xs:annotation>
        <xs:complexType>
          <xs:sequence>
            <xs:element name="Employee" maxOccurs="unbounded">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="ID">
                    <xs:simpleType>
                      <xs:restriction base="xs:string">
                        <xs:pattern value="[0-9]{5}" />
                      </xs:restriction>
                    </xs:simpleType>
                  </xs:element>
                  <xs:element name="Name" type="xs:string" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
        <xs:key name="PK_Employee_ID">
          <xs:selector xpath=".//Employee" />
          <xs:field xpath="ID" />
        </xs:key>
      </xs:element>
    </xs:schema>

    You need to observe the following fragment within the above complete schema, which actually does the restriction:

    <xs:element name="ID">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:pattern value="[0-9]{5}" />
        </xs:restriction>
      </xs:simpleType>
    </xs:element>

    The above “restriction” is of type “pattern” facet where it would allow any digit between zero and nine, and a maximum of five digits.  And not only that, it would not accept less than five digits as well!

    I strongly suggest you go through several types of patterns available in XML Schema criteria, before designing a schema.  This will help you get a better grasp of what you need to know to design powerful schema.

    More XML Articles
    More By Jagadish Chaterjee


       · Hello, I extended the XML-Schema series. enjoy and don't hesitate to post, if you...
     

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway