What Have You Gained?

[Previous] [Next]

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.

Interpreting the Content

You can also define the content in any manner you see fit. In our sample document, we added a CellContent element. You could have added numerous elements throughout the document to identify the content of each section. You could also have added attributes to existing elements. For example, you could have defined the ul element as follows:

 <ul type="" comment=""></ul> 

These additional attributes and elements can then be used by an application to catalog the content of your documents. Imagine using these tags to build the search indexes for your Web site.

These extra tags and attributes also make the document much more readable to humans. When you are designing a Web site, you can define the content of different elements rather than just drawing what the page should look like. Certain components, such as the navigation bars at the top and sides of the page and the footer section, are likely to be shared by many pages. These components can be identified and can be added to the standard template. The developer will need to change only the elements on the page that differ from one page to the next.

Reusing Elements

In our sample template, you created elements that could be used to build a Web document. When it came time to add a new row, you copied the row structure and pasted a new row into the document. This new row had the entire structure already built into it. The same technique was used to duplicate several other elements, including the li element, the font element, the p element, and the a element.

Reusing elements that contain attributes and child elements guarantees that the entire document will be uniform. When you are building documents, this uniformity will help ensure that you are following the rules for the document. Reusable elements will also make it easier to build the entire document since you are building the document from predefined pieces. For example, it would be easy to include the additional h elements by reusing the p element. You would only need to insert the h2, h3, and h4 elements and copy and paste three p elements. In this example, you are reusing the p element. Figure 3-13 illustrates this.

click to view at full size.

Figure 3-13. XML Notepad, showing added h2, h3, and h4 elements.



Developing XML Solutions
Developing XML Solutions (DV-MPS General)
ISBN: 0735607966
EAN: 2147483647
Year: 2000
Pages: 115
Authors: Jake Sturm

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net