Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML

How to Write an XML Schema

Using XML Schema to Define Your XML

By Jennifer Kyrnin, About.com

When XML first came out, there were DTDs (Document Type Definitions) that defined what the XML was going to look like and how it worked. But DTDs were written in yet another format than XML and so if you wanted to write XML applications you had to learn XML and how to write a DTD. But then along came the XML Schema language, a language written with XML. With this language, you don't have to learn a second format to define how your XML applications will work.

You can use XML to define just about any kind of text data that you might want to. For example, I might want to define a schema for the newsletter information that I send out in the Web Design / HTML newsletter.

The purpose of a schema is to define your XML document. So, the easiest way to create a schema is to start with a basic XML document that you want to define. Here's the XML I wrote for the newsletter. Andhere's the related Schema.

This document consists of a main element:

webwriter_newsletter

and five sub elements:

  • header
  • section1
  • section2
  • section3
  • section4

Each of the sub elements contains more elements, and so on down to elements like section1_linktitle1 that contain only text (or numbers or dates) with no XML elements. An element that contains a sub element is called a complex type, while elements that only contain text, numbers, or dates are called simple types. When you write your schema, you'll define the complex types and some of the simple types in your XML document.

Next page > Defining Simple Types > Page 1, 2, 3, 4, 5

Previous Features

Explore Web Design / HTML

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Web Design / HTML

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. XML
  5. Schema
  6. How to Write an XML Schema - Valid XML - XML Schemas

©2009 About.com, a part of The New York Times Company.

All rights reserved.