Labs

Lab 4.7: Tagging Rick and Stu

We said in the text that nearly any collection of information can be described usefully in XML format. This even pertains to the version of Rick and Stu's Home Page that you have been using to experiment with HTML. In the exercises that follow, we ask you to begin experimenting with this XML file.

An XML file is simply a text file, and is named with the file extension ".xml". Any text file so named can be viewed by an XML-compliant browser by simply opening it in the browser. As we noted earlier, well-formed XML files display hierarchically in the browser, with the root element at the top and the elements it contains (and the elements those elements contain and so on) indented beneath it.

Because it is a text file, you can also open an XML file using a word/text processor. As we do when working with HTML files, we recommend that you use the simplest application available on your computer so as to make sure that your XML files are always saved in text format (and NOT, for example, as Word documents, or the like). If you plan to edit an XML file you must open that file (or create it) using a word/text processor.

  1. We have taken a first stab at creating an XML version of Rick and Stu's Home Page, saved as "RickandStu.xml". Open this file now in your browser to see it displayed in hierarchical format. Then, use your word processor to open it so that you can edit it.
  2. As you can see from examining this file, it has a root element of <RICKANDSTUSHOMEPAGE>. The "children" elements of the root are <RICKSTUFF>, <STUSTUFF>, and <BOOKSHELF>, and each of these elements have children elements of their own. Listed below are a number of changes we want you to make to the file. Each one will introduce an error into the XML file. After making each change, try loading the edited XML file into the browser, and make sure that you understand the error message. "Undo" each change (that is, restore the file to its original form) before making the next change.
    1. Remove the tags <RICKANDSTUSHOMEPAGE> and </RICKANDSTUSHOMEPAGE>.
    2. Remove the tag <RICKSTUFF>.
    3. Remove the tag </BOOK> that is at the end of The Analytical Engine book entry.
    4. Reverse the order of the last </BOOK> tag and the </BOOKSHELF> tag that immediately follows it.
    5. Change the <NICKNAME> tag in element <RICKSTUFF> to read "<nickname>".
    6. Change the <AQOUTE> tag in element <STUSTUFF> to read "</aQUOTE>".
    7. Change the <BOOKSHELF> tag to read "<BOOK SHELF>" (with a space inserted between the words).
    8. Change the <RICKANDSTUSHOMEPAGE> tag to read <XMLVERSIONOFHOMEPAGE>.
  3. Now it's time for you to create some XML of your own. Using the original version of the file "RickandStu.xml", add elements to describe the following. After making each extension described below, make sure that your file is well-formed by opening it in the browser.
    1. Add a <COURSECATALOG> element to include all of the course information provided.
    2. Within the <COURSECATALOG> element, create a series of <COURSE> elements, each of which provides tags for a course's number, title, and description.
    3. Add a <FAVORITELINKS> element after the course catalog to describe a collection of your favorite links.
    4. Within the <FAVORITELINKS> element, create a series of <LINK> elements, each of which provides tags for a link's URL and its description. [Remember that these links won't work! We are writing XML - not HTML!]

Labs

MODULES:



© 2004 Thomson/Brooks Cole, All Rights Reserved.