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

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
  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

An Introduction to XML Schemas - Validating a Document
(Page 6 of 7 )

Now that you have your schema document, if you want to use it to validate a document, you have to link it to one. Open the document it is to be used with, in this case news.xml and add the following code to the root element:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="newsSchema.xsd"

This needs to be contained within the brackets of the root element, like this:

<news xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="newsSchema.xsd">

To use the location reference above, the XSD file needs to be in the same directory as the XML file. If the documents are in different directories, you’ll need to use the full path, with double forward slashes to properly escape the slash characters.

Now save the XML document and open it in a browser; the document should load as normal in IE. To use IE to actually validate the XML document using the schema, you may need to change some of the settings of IE or download an additional plug-in; see the MSDN site for further information. As Schema documents are for use mainly in XML applications, if you want to use the schema to validate a document for your own purposes, it is best to visit an on-line validator that uses the schema to validate your XML document. An excellent on-line validator can be found at the following location:


If this is the case, and your XML document uses just text, it may be wiser to use a DTD.

blog comments powered by Disqus

- 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 

Developer Shed Affiliates


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