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

Setting Policy - XML

In this concluding article, find out all about namespaces - what they are, how they work, and how you can use schemas to make sure that they're enforced in a consistent manner.

TABLE OF CONTENTS:
  1. Doing More With XML Schemas (part 4)
  2. Stocking Up
  3. The Name Game
  4. Setting Policy
  5. Old Friends And New
  6. Being Selective
  7. Closing Time
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 7
February 12, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
You can tell the validator to ensure that every element in the XML document instance is qualified with a namespace via the "elementFormDefault" attribute of the <xsd:schema> element.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.somedomain.com/ns/sw/" xmlns:sw="http://www.somedomain.com/ns/sw/" elementFormDefault="qualified"> <!-- snip ---> </xsd:schema>
This "elementFormDefault" attribute tells the validator that every element in the document instance must be qualified with a namespace identifier in order for the document to be valid. In order to verify this, you can try removing the namespace prefix from one of the <character> elements in the document instance above and validating the XML data - your validator should throw up a bunch of error messages about improperly-qualified elements.

Document authors can also satisfy this qualification requirement by specifying a default namespace for all the elements in the document instance - as in the following code segment.

<?xml version="1.0" encoding="UTF-8"?> <gallery xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.somedomain.com/ns/sw/" xsi:schemaLocation="http://www.somedomain.com/ns/sw/starwars.xsd"> <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>
If you don't necessarily want to force the document author to prefix the namespace identifier to every element in each document instance, you can turn off this requirement by specifying a value of "unqualified" for the "elementFormDefault" attribute.

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

blog comments powered by Disqus
   

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

 



© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap

Dev Shed Tutorial Topics: