XML

Cleaning Up

Many of the available elements in our template have not been used-for example, we have not used the ol elements, several h1 elements, the base element, and so on. There's no need to keep these elements, and some of them will affect the output when the document is viewed as HTML. Go through the template and delete any elements that have not been used. When you have finished, save the document. When you view the document in a Web browser, it should look like Figure 3-2.

What Have You Gained?

We've gone through quite a bit of work building this standard template and using it to create a simple Web page. The obvious question is, "Have you gained anything by doing this?" In this section, we'll look at some of the advantages of the standard template.

Manipulating the Content Automatically

Our ultimate goal is to be able to write computer applications that catalog, present, and store content in documents. Ideally, these applications should perform these tasks as an automatic process, without human intervention. You should always be able to create a computer application that automatically processes a well-formed XML document.

Ordinary HTML documents cannot be processed automatically because they are not well formed. It is extremely difficult to create HTML code according to a uniform standard. If you sketch out a design for a Web page and give it to ten different Web developers, it is likely they will create ten documents containing completely different HTML code. Even with a standard, it is likely that the code will still differ.

An automated computer application needs a standard format to work with. If every HTML document can have only a certain set of tags and these tags can appear only in a certain order, you can write an application to process the content. You could define a set of rules and pass them to your developers. In our sample XML template, we used XML and the XML Notepad to define these rules.

These rules could have simply been written in a document, but you would then have no way to verify that the ten developers all built their HTML pages according to the rules. By defining the rules as XML, you can quickly verify whether the document meets the requirements by verifying whether the document is well formed (which it must be if it is built in an XML editor). You will also need a DTD to check all the rules. (You'll learn how to build this DTD in Chapter 4.) Using XML Notepad to create the document in XML thus helps prevent errors when an application reads the document.

The elements of our sample Web page could be stored in a database. You could then create tables and fields based on the information stored in the database. Because an XML-aware computer application can identify the content of each element, the application can automatically put the correct element in the correct table and field.