XML Schema validation

XML Schema simalarity to DTD

Functionally XML Schema and DTD do the same thing. They provide a specification for XML web pages. XML web pages that conform to their corresponding XML Schema or DTD are said to be valid. So, you will find all the things we say here are very similar to what was discussed for a DTD.

XML Schema and DTD are written in different languages. An XML Schema is written in the XML language. A DTD is written in a different subset of the SGML language.

XML relationship to XML Schema

What does an XML document do?
An XML document contains the data that is being used.
For example:
The name element contains: John Smith
The address element contains: 123 Main Street, Texarkana, TX
This data could be in an employee document, that contains all the employee data for John Smith.

What does an XML Schema document do?
An XML Schema document describes an XML document.
For example:
employee must be the root element in the XML document
exactly one name element must be in the XML document
the name element must be immediatly followed by exactly one address element in the XML document
This is all similar to what was done with a DTD.

An XML document does not need to be related to an XML Schema. If it has no XML Schema to specify what the XML document must contain, then the XML document may contain anything. For example, it might contain the country of birth of the first 97 presidents of the United States of America.
The only requirement is that the XML document must be well formed, with a closing for each opening tag, et cetera.

An XML document can be related to an XML Schema.
When you relate your XML document to an XML Schema, it means you intend to meet the spcifications given in the XML Schema.
If you have done a good job, and meet all the XML Schema spcicifications, your document is valid.

Validate your XML Schema document

Your XML Schema document is itself an XML document. So you need to validate it first, before using it to validate your XML instance doucment. There are two steps to validate your XML Schema document.

  1. Check your XML Schema document, to make sure it is well formed.
    In the XML Copy Editor, check the document is well formed by using the left check mark icon.
  2. Validate your XML Schema document against the standard specification for an XML Schema.
    In the XML Copy Editor, do NOT use the right check mark icon; it would default to DTD validation.
    Inseted, select in the menu: - XML - validate - xmlschema.

Validate your XML document

There are two steps needed to validate your XML document. Always do the first step, then the second step.

Check to be sure the XML document is well formed.
This check makes sure the XML document is internally consistent.
In the XML Copy Editor, you can do this by clicking the left check mark.
Check to be sure the XML document is valid.
This check makes sure the XML document matches the requirements of the XML Schema.
In the XML Copy Editor, you can do this by clicking the right check mark.

Build good XML Schema and instance documents

Do not try to just sit down and build complete XML Schema and instance documents all at once. Use the following set of simple steps, adding a little at a time.

  1. Make a plan of approximatly what you want the XML documents to look like.
  2. Build an XML instance document with only the root element, and no other elements.
  3. Check this XML instance document to be sure it is well formed.
  4. Build a corresponding XML Schema for only the root element.
  5. Check the XML Schema document to be sure it is well formed.
  6. Check the XML Schema document to be sure it is valid.
  7. Check the XML instaance document to be sure it is valid.
  8. After successful validation, repeatedly do the following steps.
    • Add one or two things to your XML instance document.
    • Check the XML document to be sure it is well formed.
    • Make the corresponding extensions to your XML Schema.
    • Check the XML Schema document to be sure it is well formed.
    • Check the XML Schema document to be sure it is valid.
    • Check the XML document to be sure it is valid.

By taking small steps, you can correct problems as you go along. It can dificult to sort out a combination of problems that may be in the XML, or may be in the XML Schema, or may be due to an interaction of both. Taking small steps makes this much easier.

At some point in the process, you may wish to introduce an additional XML document, to test other capabilities of the XML Schema you are building.

Lab 4 assignment

Create an XML Schema document that will validate your lab 2 XML document. Design your XML Schema document carefully, so it will validate other similar XML documents.
The name of the file containing the document must be lab4.xsd

Put your web page on the Internet

You have built your DTD doucment; now put it on the Internet, so it can be used there.

Complete lab

You have built your lab 4 XML Schema document and uploaded it to voyager.
Check again to make sure the XML document on voyager is valid.
Then, send an e-mail to instructor. In the e-mail provide the following information:

  • SUBJECT: CIS 89A Lab 4
  • That you have completed Lab 4.