1. Computing

Discuss in my forum

How to Write an XML Schema

Using XML Schema to Define Your XML

By

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

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

©2014 About.com. All rights reserved.