XML
  Home arrow XML arrow Page 5 - 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 - A Complex Web
    ( Page 5 of 12 )

    Let's now look at a complex element, as illustrated by the following XML snippet

    <movie> <title>Moulin Rouge</title> <director>Baz Luhrmann</director> </movie>
    As stated above, complex elements can contain other (simple or complex) elements, and may also possess additional attributes. Corresponding to this, complex element definitions within a schema can contain definitions for other (simple or complex) elements, definitions for element attributes (if any), and references to other element definitions within the schema (more on this later).

    When defining complex types, there are again two ways in which the definition can be structured. The first involves defining a complex type, giving it a name, and then using this newly-minted type in a regular <xsd:element> declaration.

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!-- define a new datatype for a complex element --> <xsd:complexType name="complexDType"> <xsd:sequence> <xsd:element name="title" type="xsd:string"/> <xsd:element name="director" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <!-- create an element of this type --> <xsd:element name="movie" type="complexDType" /> </xsd:schema>
    The second option involves combining the two steps above into a single step - the definition of the complex element is embedded within the <xsd:element> declaration itself.

    Here's how the XML snippet above would be represented in a schema.

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="movie"> <!-- this complex element definition has no name, and is referred to as an "anonymous" element --> <xsd:complexType> <xsd:sequence> <xsd:element name="title" type="xsd:string"/> <xsd:element name="director" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
    The advantage of creating a named type should be obvious - the new type, once defined, can be used in multiple places within the schema simply by referencing it by name. The following example illustrates this:

    <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> <xsd:element name="movie"> <!-- this complex element definition has no name, and is referred to as an "anonymous" element --> <xsd:complexType> <xsd:sequence> <!-- simple elements using built-in types --> <xsd:element name="title" type="xsd:string"/> <xsd:element name="director" type="xsd:string"/> <!-- simple element using new derived type --> <xsd:element name="rating" type="simpleDType"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>


     
     
    >>> 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 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek