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

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

Designing Your own XML Schema: Restrictions and User Defined Types - User-defined Complex Type in XML Schema
(Page 7 of 7 )

In the previous sections, we dealt only with simple user-defined types.  Now, we shall deal with the user-defined complex type.

Let us consider that I would like to define my own data type called “AddressType,” which holds Street, City and Zip elements.  After defining “AddressType,” I would like to use it with two elements, “ResAddress” (residential address) and “OffAddress” (Office Address) as part of the “Employee” definition.  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=
  <xs:element name="Employees">
      <xs:documentation>Contains All Employee information</xs:documentation>
        <xs:element name="Employee" maxOccurs="unbounded">
              <xs:element name="ID" type="xs:string">
              <xs:element name="Name" type="xs:string" />
              <xs:element name="ResAddress" type="AddressType" />
              <xs:element name="OffAddress" type="AddressType" />
    <xs:key name="PK_Employee_ID">
      <xs:selector xpath=".//Employee" />
      <xs:field xpath="ID" />
  <xs:complexType name="AddressType">
      <xs:element name="Street" type="xs:string" />
      <xs:element name="City" type="xs:string" />
      <xs:element name="zip" type="xs:string" />

Any comments, suggestions, feedback, bugs, errors are highly appreciated at jag_chat@yahoo.com

DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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