A valid XML document is validated against a Document Type Definition (DTD) or XML Schema. These are a set of rules created by the developer or a standards organization that define the semantics of the XML document. These tell the computer what to do with the markup.
In the case of the About Markup Language, since this is not a standard XML language, like XHTML or SMIL, the DTD would be created by the developer. That DTD would most likely be on the same server as the XML document, and referenced at the top of the document.
Before you start developing a DTD or Schema for your documents, you should realize that simply through being well-formed, an XML document is self-describing, and thus doesn't need a DTD.
For example, with our well-formed AML document, there are the following tags:
- <newsletter>
- <long_title>
- <filename>
- <section1_linktitle1>
- <section1_url1>
- <section1_annotation1>
If you are familiar with the Web Writer newsletter, you may recognize the different sections of the newsletter. This makes it very easy to create new XML documents using the same standard format. I know that I would always put the full long title in the <long_title></long_title> tag, and the first section URL in the <section1_url1></section1_url1> tag.
DTDs
If you are required to write a valid XML document, either to use the data or to process it, you would include it in your document with the <!DOCTYPE> tag. In this tag, you define the base XML tag in the document, and the location of the DTD (usually a Web URI). For example:
<!DOCTYPE newsletter SYSTEM "aml-newsletter.dtd">
One nice thing about DTD declarations is that you can declare that a DTD is local to the system where the XML document is with the "SYSTEM". You can also point to a public DTD, such as with an HTML 4.0 document:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
When you use both, you are telling the document to use a specific DTD (the public identifier) and where to find it (the system identifier).
Finally, you can include an internal DTD directly in the document, within the DOCTYPE tag. For example (this is not a complete DTD for the AML document):
<!DOCTYPE newsletter
[
<!ENTITY long_title (#PCDATA)>
<!ENTITY filename (#PCDATA>
<!ENTITY volume (#PCDATA)>
<!ENTITY meta_title (#PCDATA)>
<!ENTITY meta_description (#PCDATA)>
<!ENTITY meta_keywords (#PCDATA)>
<!ENTITY section1 (section1_title | section1_linktitle1 | section1_url1 | section1_annotation1 | section1_toc1>
]>
XML Schema
In order to create a valid XML document, you can also use an XML Schema document to define your XML. XML Schema is an XML document that describes XML documents. Learn how to write a schema.
Note
Just pointing to a DTD or XML Schema is not enough. The XML that is in the document must follow the rules in the DTD or Schema. Using a validating parser is a simple way to check that your XML is following the DTD rules. You can find many such parsers online.
First page > Making it Well-Formed > Page 1, 2

