Everyday Computing Advanced Computing The Internet At Home Health, Mind & Body Making & Managing Money Sports & Leisure Travel Beyond The Classroom
Building Web Sites
Doing Business Online
Graphics & Animation
Using the Internet
Moms, Dads, and Grads -- Win $500!
XML For Dummies, 4th Edition
Understanding XML Schemas
Adapted From: XML For Dummies, 4th Edition

A schema lays down the rules a valid XML document should follow to ensure that the information contained in the XML document is in the right form. In effect, the schema acts like a template, specifying the form that the XML document must take. When a program processes an XML document written against a schema, it validates (compares and checks) the document against the schema.

You can build schema documents from scratch, but you can also reuse schemas -- either the ones you’ve created or third-party schemas that are available from industry groups.

Schemas are stored in a totally separate file from the XML documents they govern. You can’t combine a schema and its XML document into a single file. A schema consists of declarations for elements and attributes and specifies how those elements and attributes work together to define content and to establish a document structure. A schema also allows you to restrict the content of these elements and attributes by using and defining very specific datatypes.

An XML Schema document includes the following parts:

  • XML declaration (Syntax: xml version="version" encoding="encoding"): Tells the processor which version of XML and which character encoding to use.
  • Schema element (Syntax: xsd:schema xmlns:xsd="namespace"): Identifies the document as XML Schema.
  • Element declaration (Syntax: xsd:element name="name"): Defines the element named name.
  • Attribute declaration (Syntax: xsd:attribute name="name" type="datatype"): Defines the attribute named name.

Even if you don’t plan on writing your own schemas, it helps to know how to read and understand them. You should be able to look at a schema, list all the elements, attributes, and datatypes, and understand how and when to use those elements and attributes and how to format the data in your XML document.

Unlike a DTD (Document Type Definition), schemas are simply XML documents that use XML's standard markup syntax to define the structure for other documents. When you write a schema, you’re simply writing XML. This means you don't have to learn a new language; you only have to learn how to use a particular set of XML elements and attributes.


To find out how to have Dummies eTips delivered to your e-mail inbox every week, visit the Dummies eTip Sign-Up Page.
Related Articles
Knowing Why Java and XML Mesh
Parsing XML Events with SAX
Taking the Document Object Model (DOM) Approach to XML Documents
Building Custom Code with Java API for XML Binding (JAXB)
Addressing Ajax Design Issues
Related Titles
XHTML For Dummies
XML All-in-One Desk Reference For Dummies
Java and XML For Dummies
XSLT For Dummies
XML For Dummies, 4th Edition