Home arrow XML arrow Page 6 - Designing Your own XML Schema: Learn the Essentials
XML

Designing Your own XML Schema: Learn the Essentials


This is the first article in a series which guides you in designing XML Schemas right from the basics without any hurdles.

Author Info:
By: Jagadish Chaterjee
Rating: 4 stars4 stars4 stars4 stars4 stars / 22
March 06, 2006
TABLE OF CONTENTS:
  1. · Designing Your own XML Schema: Learn the Essentials
  2. · XML Schema: beginning with the simplest way
  3. · XML Schema: the complex way
  4. · XML Schema: a simple practical example
  5. · XML Schema: a simple practical example continued
  6. · XML Schema: a more practical example

print this article
SEARCH DEVARTICLES

Designing Your own XML Schema: Learn the Essentials - XML Schema: a more practical example
(Page 6 of 6 )

I shall conclude this article with one more practical “complex” example.  Let us have a look at the following XML schema now:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
      <xs:element name="EmployeeDetails">
            <xs:annotation>
                  <xs:documentation>Comment describing your root element</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="Address" maxOccurs="3">
                                                <xs:complexType>
                                                      <xs:sequence>
                                                            <xs:element name="Street" type="xs:string"/>
                                                            <xs:element name="City" type="xs:string"/>
                                                            <xs:element name="State" type="xs:string"/>
                                                      </xs:sequence>
                                                </xs:complexType>
                                          </xs:element>
                                    </xs:sequence>
                              </xs:complexType>
                        </xs:element>
                  </xs:sequence>
            </xs:complexType>
      </xs:element>
</xs:schema>

According to the above example, the document root element would be “EmployeeDetails.”  The element “EmployeeDetails” internally can contain “Employee” elements.  The element “Employee” internally contains three more elements: “ID,” “Name” and “Address.”   “Address” is again a complex type and internally contains the elements “Street,” “City” and “State”.

You should observe that there could be any number of “Employee” elements within “EmployeeDetails.”  And finally you can have a maximum of three “Address” elements for each “Employee.”

You should also observe that “ID,” “Name,” “Street,” “City” and “State” are defined with “simple types” rather than with “complex types.”  The only complex elements are “EmployeeDetails,” “Employee” and “Address.”

Now, how would the XML document look when it conformed to the above XML Schema?  The following would be a sample XML document which conforms to the XML Schema above.

<?xml version="1.0" encoding="UTF-8"?>
<EmployeeDetails xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\EmployeeDetails.xsd">
      <Employee>
            <ID>1001</ID>
            <Name>Jag</Name>
            <Address>
                  <Street>13-20-26, Gunupudi</Street>
                  <City>Bhimavaram</City>
                  <State>Andhra Pradesh</State>
            </Address>
            <Address>
                  <Street>Nallam vari thota</Street>
                  <City>BVRM</City>
                  <State>AP, India</State>
            </Address>
      </Employee>
      <Employee>
            <ID>1002</ID>
            <Name>Winner</Name>
            <Address>
                  <Street>11-11-11, </Street>
                  <City>Bhimavaram</City>
                  <State>Andhra Pradesh</State>
            </Address>
      </Employee>
</EmployeeDetails>

Any comments, suggestions, feedback, bugs, errors are highly appreciated at jag_chat@yahoo.com


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
XML ARTICLES

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- 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

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials