CS 130 Lab #8: Designing Data Structures
The purpose of this lab is to develop understanding of and experience with the
design of abstract data structrues (in XML) and their transformations (via XSL),
especially the specific notion of transformation to duocment structures (HTML).
There are three parts to the lab, one which asks you to design a data structure
in XML to represent albums and songs, another which asks you to represent a
specific music list as an outline-style document, and finally a
tabular display of selected songs from the list.
Note that different browsers (FireFox, Internet Explorer, Netscape, etc.)
may display things differently I have tested the basic XML and XSL features
used here and in the textbook and found that Internet Explorer seems to work best.
Note: you can find the sample files from lecture (galaxies,
inhabited planets, atmospheric gasses) at this link.
That's the whole folder, just open the files you want in either WordPad
(to see the "inner workings" or in Internet Explorer (to see how it looks in a browser).
Designing an XML data structure for music lists
Working in a text editor such as WordPad, you should write a text document
(but save it with the "
.xml" extension) which describes a
music list such as might be found on a typical MP3 player.
The list should be structured according to musical genres
(e.g., Rock, Pop, Country, Hip-hop, etc.);
within each genre there should be a set of albums, each with a:
- a set of songs
- and an optional "Explicit" designation (to keep kids away from
- and any other information you would like to include
In addition, each song should have a:
- a duration (e.g., "5:23")
- a priority number (specifying whether it is currently favored or
not), from 1 to 5 (1 is best).
Once you have your structure, you should be able to check it by displaying it in
the default "outline" format used for XML documents without a style just by
opening it in Internet Explorer. You will want to do this periodically as
you work, just to check that your structure is well-formatted.
What sorts of tagging structure should you use? Which things should be
tags and which should be attributes? How should things be nested one inside
the other? This is really up to you: you should look to
the classroom lecture examples for guidance, and try to anticipate the
need to extract parts of the data in the later parts of this lab. But there
are in some sense no "right" answers: you may design any structure you wish.
What sorts of albums and songs should you include? This is really up to you:
just be sure to have fun with it! You can use real artists and albums you know,
or make up fun or silly ones (even serious ones, if you really want).
For your final demo, you should have at least 5 albums in at least 3
genres. You can put in just one song for an album, if you like, but at least
some albums should have a few songs. At least some of these should have optional
information (the "Explicit" lyrics marker).
Some common problems:
Here is a list of some common problems people are having in lab, just to save time
(special thanks to all those "guinea pigs" who started the lab already
and helped point these out):
- Recommended overall approach
Try getting a small number of albums/songs
tagged up first, so they open as a "clickable outline (see below) in
a web browser first. Next try to write enough XSL to just get out
a single, fixed title, then add just the genre names, then the
album titles, etc. In other words, proceed in phases, as we did in lecture.
Finally, when you have all the XSL working, try adding some more
actual albums to fill out the list (it'll be a lot easier to do this
once you have the final XML structure worked out, which you probably
won't have settled until you get the XSL working right).
- Tags names must be a single "word" (but may be hyphenated).
So, for example, a tag like
won't work, but you can use
- Tags cannot be their own attributes.
So you can't write
<band="rad">, but you can
<band status="rad"> or even
<band name="foo-fighters" status="rad">.
- Want to see your XML file in "clickable outline" style?
Just leave out the xml/xsl tags at the top, as in
this modified galaxy file from lecture.
This step can be a big help in making sure your XML is properly tagged.
- Getting weird things in error meesages like "
You probably saved your file as RTF (Rich Text Format) from WordPad instead
of as a Text document (remember, from WordPad you should always save as
a text document, then replace the "
.txt" extension with
.xml" or "
.xsl", just as for html files from the last lab).
Transforming album list data into an outline document
Again working in a text editor such as WordPad, you should write an XSL
stylesheet which allows your album list to be displayed in an outline-style
format (as for the galaxies example from lecture).
Your design is largely up to you, but it should have at least these features:
- genres should appear as level-2 headers (H2 tags);
- albums within a genre should either be lower
level header tags or unordered lists;
- song titles should appear in bold/strong at the beginning of the
- "explicit" warning notes should appear in some easily-identifiable way
(italicized or bold, or both; perhaps even in a color like red);
Please have your files and pages ready to demo by the end of lab on
Monday 24 April.