XML
  Home arrow XML arrow Page 6 - Doing More With XML Schemas (part 4)
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 
IBM developerWorks
 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 4)
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2003-02-12

    Table of Contents:
  • Doing More With XML Schemas (part 4)
  • Stocking Up
  • The Name Game
  • Setting Policy
  • Old Friends And New
  • Being Selective
  • Closing Time

  • 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

    Doing More With XML Schemas (part 4) - Being Selective


    (Page 6 of 7 )

    The previous examples have demonstrated how a schema designer can force a document author to qualify an XML document with appropriate namespaces. However, based on what we've seen thus far, this is an all-or-nothing proposition - either every element is qualified or every element is unqualified - which is not very practical for real-world use.

    Fortunately, the XML Schema specification also provides a "form" attribute for each element and attribute definition, which allows you to specify qualification rules on a case-by-case basis. Consider the following example, which demonstrates:

    <?xml version="1.0" encoding="UTF-8"?> <xsd:schema targetNamespace="http://www.somedomain.com/ns/sw/" xmlns:sw="http://www.somedomain.com/ns/sw/" 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" form="qualified"/> <xsd:element name="species" type="xsd:string" form="unqualified"/> <xsd:element name="language" type="xsd:string" form="unqualified"/> <xsd:element name="home" type="xsd:string" form="qualified"/> </xsd:sequence> </xsd:complexType> <!-- define the root element and its contents --> <xsd:element name="gallery"> <xsd:complexType> <xsd:sequence> <xsd:element name="character" type="sw:starWarsEntity" maxOccurs="unbounded" form="qualified"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
    As you can see, I've introduced the "form" attribute into the element definitions above. Like its schema-level cousins, this attribute too takes two values: "qualified" and "unqualified". In the example above, the <character>, <name> and <home> elements are all to be qualified with namespaces; the others may remain unqualified.

    And here's an XML document instance conforming to the schema above:

    <?xml version="1.0" encoding="UTF-8"?> <sw:gallery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sw="http://www.somedomain.com/ns/sw/" xsi:schemaLocation="http://www.somedomain.com/ns/sw/starwars.xsd"> <sw:character> <sw:name>Luke Skywalker</sw:name> <species>Human</species> <language>Basic</language> <sw:home>Tatooine</sw:home> </sw:character> <sw:character> <sw:name>Chewbacca</sw:name> <species>Wookie</species> <language>Shyriiwook</language> <sw:home>Kashyyyk</sw:home> </sw:character> <sw:character> <sw:name>Chief Chirpa</sw:name> <species>Ewok</species> <language>Ewok</language> <sw:home>Endor</sw:home> </sw:character> </sw:gallery>
    The XML Schema author can thus selectively enforce XML element qualification - useful if only some of the elements are likely to clash with others.

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