XML
  Home arrow XML arrow Page 4 - Understanding XML Schema
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
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? 
Google.com  
XML

Understanding XML Schema
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2001-10-15


    Table of Contents:
  • Understanding XML Schema
  • The Next Generation
  • An Evening At The Moulin Rouge
  • Simple Simon
  • A Complex Web
  • Nesting Season
  • Battle Of The Sexes
  • Dealing With The Ref
  • Different Flavours
  • When In Rome...
  • Test Drive
  • The Next Step

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    Understanding XML Schema - Simple Simon
    ( Page 4 of 12 )

    With the broad overview out of the way, let's now focus on the different elements (pun definitely intended!) that make up a schema.

    The XML Schema specification makes a basic distinction between "simple" and "complex" elements. Simple elements cannot contain other elements or possess additional attributes; complex elements can have additional attributes and serve as containers for other elements (which themselves may be either simple or complex).

    Within a schema, these two element types are represented by the <xsd:simpleType> and <xsd:complexType> elements respectively.

    Simple elements can be represented in two ways. The first (and simplest) method is to use the <xsd:element> declaration with a built-in datatype - the following simple element

    <title>Moulin Rouge</title>
    would be represented in a schema by

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="title" type="xsd:string"/> </xsd:schema>
    When the datatype name is preceded by the "xsd:" prefix, it indicates a predefined datatype and not a new, user-defined type. The XML Schema specification lists about forty different built-in datatypes, including "string", "integer", "decimal", "float", "boolean", "time", "date", "dateTime" and "anyURI". However, in case these are too generic for you, it's also possible to derive your own custom datatype from the built-in ones, and then declare simple elements using this custom datatype.

    Consider the following schema definition, which is equivalent to the one above:

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!-- define a new datatype --> <xsd:simpleType name="simpleDType"> <xsd:restriction base="xsd:string"></xsd:restriction> </xsd:simpleType> <!-- declare an element of this type --> <xsd:element name="title" type="simpleDType"/> </xsd:schema>
    Typically, this second method is used only when a schema author needs to restrict the values of a particular simple element over and above the constraints inherent in a specific datatype. Here's a more constructive definition, which restricts the values of the "rating" element to an integer between 1 and 10.

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!-- define a new datatype --> <xsd:simpleType name="simpleDType"> <xsd:restriction base="xsd:integer"> <!-- restrict integer values between 1 and 10 --> <xsd:minInclusive value="1"/> <xsd:maxInclusive value="10"/> </xsd:restriction> </xsd:simpleType> <!-- declare an element of this type --> <xsd:element name="rating" type="simpleDType"/> </xsd:schema>
    I'll be discussing the derivation of new datatypes in more detail a little further down, so don't worry too much if the syntax seems a little unfamiliar. The important thing to note here is the two different options open to you while defining a simple element.

     
     
    >>> More XML Articles          >>> More By Harish Kamath, (c) Melonfire
     

       

    XML ARTICLES

    - Flex Array Collection Sort and Filtering
    - The Flex Tree Control
    - Flex List Controls
    - Working with Flex and Datagrids
    - How to Set Up Podcasting and Vodcasting
    - Creating an RSS Reader Application
    - Building an RSS File
    - An Introduction to XUL Part 6
    - An Introduction to XUL Part 5
    - An Introduction to XUL Part 4
    - An Introduction to XUL Part 3
    - An Introduction to XUL Part 2
    - An Introduction to XUL Part 1
    - XML Matters: Practical XML Data Design and M...
    - Practical XML Data Design and Manipulation f...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek