Home arrow XML arrow Page 7 - An Introduction to XML Schemas
XML

An Introduction to XML Schemas


XML Schemas help you control what elements appear in your XML documents. Similar to Document Type Definitions, they offer distinct advantages over the older syntax. Dan Wellman provides a basic overview, with examples to get you started working on your own.

Author Info:
By: Dan Wellman
Rating: 5 stars5 stars5 stars5 stars5 stars / 13
November 03, 2004
TABLE OF CONTENTS:
  1. · An Introduction to XML Schemas
  2. · Choose Your Schema
  3. · Element Declarations
  4. · Definitions and Elements
  5. · The Complete File
  6. · Validating a Document
  7. · A Few Final Tips

print this article
SEARCH DEVARTICLES

An Introduction to XML Schemas - A Few Final Tips
(Page 7 of 7 )

When creating your own schema documents, it is a good idea to use annotations to provide instructions in a human-readable format. Annotations are just like HTML comments; to add an annotation, you need to add an <annotation> element and a documentation element to enclose the annotation. For example, we could change our root element declaration to read as:

<xsd:element name="news">
  <xsd:annotation>
  <xsd:documentation xml:lang="en">
 This is a collection of news items
  </xsd:documentation>
  </xsd:annotation>
  <xsd:complexType>
  <xsd:sequence maxOccurs="unbounded">
    <xsd:element ref="article"/>
  </xsd:sequence>
  </xsd:complexType>
</xsd:element>

There is much, much more you can do with a schema document; this is just intended as an introduction. Using a schema for such a simple document in the real world would be a bit of a waste--look at how much code is needed. Remember the DTD for the news.xml document from the XML article? If not, it was only about five lines of code long, as opposed to the 20 that you’ve just typed out. Schemas are so useful, however, when dealing with data centric documents using many different types of data, that it is worth taking the time to learn how to use them.


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