XML
  Home arrow XML arrow Page 5 - Designing Your own XML Schema: Learn the E...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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

Designing Your own XML Schema: Learn the Essentials
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2006-03-06

    Table of Contents:
  • Designing Your own XML Schema: Learn the Essentials
  • XML Schema: beginning with the simplest way
  • XML Schema: the complex way
  • XML Schema: a simple practical example
  • XML Schema: a simple practical example continued
  • XML Schema: a more practical example

  • 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


    Designing Your own XML Schema: Learn the Essentials - XML Schema: a simple practical example continued


    (Page 5 of 6 )

    In the previous section, I used only one employee detail in the XML document.  Can we have more than one employee provided in the XML document according to the previous schema?  The answer is NO.  By default, every element can occur only once.  We need to make a small modification to the above schema to make it accept a larger number of employee details.  The modification could be as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
          <xs:element name="Employees">
                <xs:annotation>
                      <xs:documentation>Contains All Employee information</xs:documentation>
                </xs:annotation>
                <xs:complexType>
                      <xs:sequence>
                            <xs:element name="Employee" maxOccurs="unbounded">
                                  <xs:complexType>
                                        <xs:sequence>
                                              <xs:element name="ID" type="xs:string"/>
                                              <xs:element name="Name" type="xs:string"/>
                                              <xs:element name="Age" type="xs:int"/>
                                        </xs:sequence>
                                  </xs:complexType>
                            </xs:element>
                      </xs:sequence>
                </xs:complexType>
          </xs:element>
    </xs:schema>

    Now you should observe the word “maxOccurs.”  By default “maxOccurs” is set to 1.  This means you can have only one employee detail provided within the XML document.  Now, we specified “maxOccurs” with “unbounded.”  This means a countless number of employee details can be provided within the XML document.

    Let us check this with a sample XML document conforming to the above schema now.

    <?xml version="1.0" encoding="UTF-8"?>

    <Employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Employees.xsd">
          <Employee>
                <ID>1001</ID>
                <Name>Jag</Name>
                <Age>27</Age>
          </Employee>
          <Employee>
                <ID>1001</ID>
                <Name>Jag</Name>
                <Age>27</Age>
          </Employee>
          <Employee>
                <ID>1003</ID>
                <Name>Dhan</Name>
                <Age>48</Age>
          </Employee>
    </Employees>

    Now, you can see that I am able to add any number of employees with the above-defined schema.

    More XML Articles
    More By Jagadish Chaterjee


       · Hello guys, you can learn easily XML schema from this series. Have a look at it and...
     

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







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