Home arrow XML arrow Page 3 - Designing Your own XML Schema: Restrictions and User Defined Types
XML

Designing Your own XML Schema: Restrictions and User Defined Types


This is the third article in a series which guides you in designing XML Schemas. Hopefully this series will take you from the most basic ideas to the more advanced topics without any hurdles.

Author Info:
By: Jagadish Chaterjee
Rating: 5 stars5 stars5 stars5 stars5 stars / 11
March 20, 2006
TABLE OF CONTENTS:
  1. · Designing Your own XML Schema: Restrictions and User Defined Types
  2. · Restrictions based on patterns in XML Schema
  3. · How to define your own simple type (user-defined data type) in XML Schema
  4. · Understanding the user-defined simple type in XML Schema
  5. · User-defined Simple Type with enumeration in XML Schema
  6. · Understanding the simple type with enumeration in XML Schema
  7. · User-defined Complex Type in XML Schema

print this article
SEARCH DEVARTICLES

Designing Your own XML Schema: Restrictions and User Defined Types - How to define your own simple type (user-defined data type) in XML Schema
(Page 3 of 7 )

This is another interesting topic in XML Schema.  The XML Schema vocabulary was already defined with plenty of data types, together with “restriction” facets to support broad varieties of information.  But there always exists some room for enhancements. 

XML Schema vocabulary is extensible.  This means you can also define (or extend) your own vocabulary from the existing one.

Coming to our scenario, let us consider that I would like to define my own data type called “AgeType” exclusively for the “Age” element.   The following listing of a complete XML Schema does the same:

<?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" type="xs:string">
              </xs:element>
              <xs:element name="Name" type="xs:string" />
              <xs:element name="Age" type="AgeType" />
            </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:simpleType name="AgeType">
    <xs:restriction base="xs:integer">
      <xs:minInclusive value="1" />
      <xs:maxInclusive value="100" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

I shall explain the above schema in the next section.


blog comments powered by Disqus
XML ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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