XML
  Home arrow XML arrow Page 6 - 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  
Mobile Linux 
App Generation ROI 
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 - Understanding the simple type with enumeration in XML Schema


    (Page 6 of 7 )

    Instead of explaining the whole XML schema at one time (demonstrated in the previous section), let me elaborate in a few steps.  Let us consider the following fragment first:

          <xs:simpleType name="Category">
            <xs:restriction base="xs:string">
              <xs:enumeration value="TopManagement" />
              <xs:enumeration value="Management" />
              <xs:enumeration value="SalesMan" />
              <xs:enumeration value="Clerk" />
            </xs:restriction>
          </xs:simpleType>

    The above fragment declares a new data type (of the simple type in XML schema).  The name of the new simple data type is “Category.”  Once declared, I can use this “Category” as a data type for any element in my XML Schema.

    In general, every new user-defined type will get inherited from an existing XML Schema type.  According to the above scenario, our “Category” is getting inherited from the “string” type (xs:string).  This means all the characteristics of “xs:string” become available to our new data type “Category.” 

    Once inherited from an existing type, we can refine with our own restrictions along with facets (if necessary).  According to the above definition, I restricted the “Category” in such a way that it would accept any of the values within the following list (or enumeration):

          <xs:enumeration value="TopManagement" />
          <xs:enumeration value="Management" />
          <xs:enumeration value="SalesMan" />
          <xs:enumeration value="Clerk" />

    Now I need to use the new data type in my element definitions (in our sense, it would be “EmpCategory” element).  Let us look at the following fragment:

    <xs:element name="EmpCategory" type="Category" />

    The above line declares a new element, “EmpCategory,” which is based on our own user-defined simple type “Category.”  And thus all the restrictions available for “Category,” get carried to the “EmpCategory” element accordingly for validations (based on enumeration values).  You can use the same “EmpCategory” any number of times within the same schema.  Availability of “Category” to external schemas is also possible through namespaces and other means, which I will cover in future articles.

    You can also create several other new data types, which can even nest some other data types.  Similarly, you can even create a data type based on some elements.  This would help us to reuse every data type in several other schemas when necessary.

    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 4 hosted by Hostway
    Stay green...Green IT