Home arrow XML arrow Page 2 - Doing More With XML Schemas (part 2)

Feeling The Force - XML

In this second part, find out how to derive new element types by constraining existing ones, control access to your schema definitions, and redefine externally-provided schemas in place.

TABLE OF CONTENTS:
  1. Doing More With XML Schemas (part 2)
  2. Feeling The Force
  3. The Next Level
  4. Big Brother Is Watching...
  5. Speaking In The Abstract
  6. Going Local
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 5
January 23, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
In "The Phantom Menace", when Qui-Gon Jinn first meets Anakin Skywalker on an unscheduled stop at the Outer Rim world of Tatooine, he immediately realizes that there is something special about the boy: he is destined to be a Jedi.

Or is he?

"The Phantom Menace" and subsequent episodes certainly resolve that question conclusively - but what does that have to do with XML schemas?

Quite a lot, as you'll see shortly. First, though, let's quickly revisit a segment from the first part of this article, in which I defined a complex data type named "starWarsEntity",


<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <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> <!-- more definitions --> </xsd:schema>


and then extended it to create a new "Human" sub-type.


<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="Human"> <xsd:complexContent> <xsd:extension base="starWarsEntity"> <xsd:sequence> <xsd:element name="gender" type="xsd:string"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <!-- more definitions --> </xsd:schema>


Let's now extend things a little further, and derive one more datatype from the "Human" complex type - we'll call this one "Jedi", and make sure that it inherits all the characteristics of the "Human" type, together with one additional attribute. Here's the definition:


<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:complexType name="Jedi"> <xsd:complexContent> <xsd:extension base="Human"> <xsd:sequence> <xsd:element name="midichlorian-count" type="xsd:integer"/> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> <!-- more definitions --> </xsd:schema>


In case you're wondering - midi-chlorians are microscopic symbiotic creatures that swim around in the bloodstream of creatures in the Star Wars universe. In Star Wars lore, every Jedi possesses an unusually large number of these creatures, which are the reason they are so receptive to the Force; in "The Phantom Menace", Qui-Gon Jinn uses this midi-chlorian count to determine Anakin's eligibility for Jedi-hood.

Here's an XML file built around this schema:


<?xml version="1.0" encoding="UTF-8"?> <gallery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <character xsi:type="Jedi"> <name>Luke Skywalker</name> <species>Human</species> <language>Basic</language> <home>Tatooine</home> <gender>Male</gender> <midichlorian-count>9000</midichlorian-count> </character> </gallery>


What I just showed you was an example of deriving, by extension, one new type from another existing type, which is itself derived from a base type. This type of extensibility is what makes XML Schemas so powerful...and so easy to maintain.

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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

XML ARTICLES

- Google Docs and Xpath Data Functions
- 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...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: