XML
  Home arrow XML arrow Page 6 - Understanding XML Schema
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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? 
XML

Understanding XML Schema
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Understanding XML Schema - Nesting Season


    (Page 6 of 12 )

    If a complex element contains child elements, these child element definitions appear nested within a <xsd:sequence> element. In the previous example, the elements nested within the "movie" container element are all simple elements; however, it's also possible to have nested complex elements, as in the following XML document:

    <?xml version"1.0"?> <movie> <title>Moulin Rouge</title> <cast> <person>Nicole Kidman</person> <person>Ewan McGregor</person> </cast> </movie>
    In this case, the element "cast", which contains child elements of its own, is nested within the "movie" element, which is itself a complex element. The corresponding schema definition would look like this:

    <?xml version"1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="movie"> <xsd:complexType> <xsd:sequence> <!-- simple element definition --> <xsd:element name="title" type="xsd:string"/> <!-- complex element definition --> <xsd:element name="cast"> <xsd:complexType> <xsd:sequence> <xsd:element name="person" type="xsd:string" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
    In case you're wondering, the "maxOccurs" attribute is used to specify the maximum number of occurrences of the corresponding element (there's a corresponding "minOccurs" attribute to control the minimum number of occurrences). Both these attributes default to 1, unless they're explicitly assigned a value. And just incidentally, you can't achieve this level of precision with a DTD.

    In this particular example, a value of "unbounded" for the "maxOccurs" attribute allows for an infinite number of "person" elements in the document instance.

    It's also possible to make certain elements optional. In order to illustrate this, let's add a couple of new elements to the schema definition above - a "release_date" element of type "date", and a "rating" element of type "integer". And let's also make the "release_date" element optional, through judicious use of the "minOccurs" and "maxOccurs" attributes.

    <?xml version"1.0"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="movie"> <xsd:complexType> <xsd:sequence> <!-- simple element definition --> <xsd:element name="title" type="xsd:string"/> <!-- complex element definition --> <xsd:element name="cast"> <xsd:complexType> <xsd:sequence> <xsd:element name="person" type="xsd:string" maxOccurs="unbounded"/> </xsd:sequence> </xsd:complexType> </xsd:element> <!-- simple element definition --> <xsd:element name="release_date" type="xsd:date" maxOccurs="1" minOccurs="0"/> <!-- simple element definition --> <xsd:element name="rating" type="xsd:integer"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>

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


     

       

    XML ARTICLES

    - 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...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway