Home arrow XML arrow Page 5 - Designing Your own XML Schema: Restrictions and User Defined Types
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Designing Your own XML Schema: Restrictions and User Defined Types - User-defined Simple Type with enumeration in XML Schema
(Page 5 of 7 )

In the previous two sections, we dealt with only the simple type without enumeration.  Now, we shall deal with user-defined simple types with the enumeration facet.

Let us consider that I would like to define my own data type called “Category,” which holds all types of employee categories (in the form of an enumeration).  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="EmpCategory" type="Category" />
            </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="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>
</xs:schema>

I shall explain the above schema in the next section.


blog comments powered by Disqus
XML ARTICLES

- 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
- Simple Web Syndication with RSS 2.0
- Java UI Design with an IDE

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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