XML
  Home arrow XML arrow Page 3 - Doing More With XML Schemas (part 1)
Click Here
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 
SunQuest
 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

Doing More With XML Schemas (part 1)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 5
    2003-01-07

    Table of Contents:
  • Doing More With XML Schemas (part 1)
  • A Complex Web
  • Nesting Season
  • Extending Yourself
  • Filing It All Away

  • 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

    At the virtual BlackBerry Technical Seminar 2008, you can ask your development questions directly of Research In Motion® (RIM) experts, and take advantage of learning opportunities designed uniquely for BlackBerry solution developers. Register Today!

    Doing More With XML Schemas (part 1) - Nesting Season


    (Page 3 of 5 )

    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 "character" 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" encoding="UTF-8"?> <gallery> <character> <name>Luke Skywalker</name> <species>Human</species> <language>Basic</language> <home>Tatooine</home> </character> <character> <name>Chewbacca</name> <species>Wookie</species> <language>Shyriiwook</language> <home>Kashyyyk</home> </character> <character> <name>Chief Chirpa</name> <species>Ewok</species> <language>Ewok</language> <home>Endor</home> </character> </gallery>
    In this case, the element "character", which contains child elements of its own, is nested within the "gallery" element, which is itself a complex element containing many instances of "character". The corresponding schema definition would look like this:

    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!-- define a complex type --> <xsd:complexType name="starWarsEntity"> <xsd:sequence> <xsd:element name="name" type="xsd:string"/> <xsd:element name="species" type="xsd:string"/> <xsd:element name="language" type="xsd:string"/> <xsd:element name="home" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <!-- define the root element and its contents --> <xsd:element name="gallery"> <xsd:complexType> <xsd:sequence> <xsd:element name="character" type="starWarsEntity" maxOccurs="unbounded"/> </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.

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

    I could also use the second technique discussed on the previous page to create a schema definition without using a named type. I'll leave this to you as an exercise, since it's usually better to name your types as you create them for greater re-use value.

    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 3 hosted by Hostway