Chapter 4. Schemas – Syntax

Exercises

Note:

Choose one editor, such as XMLSpy or the oXygen XML Editor, install it on your computer prior to practicing the exercises for this Chapter.

A wide variety of XML tools are available from the W3C XML Web site: http://www.w3.org/XML/Schema#Tools.

For XML schema and record examples, refer to the W3Schools' XML Schema Tutorial (http://www.w3schools.com/schema/default.asp).

Option 1

Option 1. Create an XML schema and apply to record creation

1. Many online music sites offer brief descriptions for “albums” and track information contained in these albums (e.g., in CD format). The following descriptive elements are typical data presented to users:

Artist (or artists) Date of release Rating
Album title Publisher Track names
Genre Price  

Before you start creating the schema file, analyze the eight elements (listed above) to determine:

  • whether there are any subelements, or whether an element needs a set of pre-defined values (enumerated values).
  • whether an element is mandatory or optional.
  • whether an element is repeatable.

Use an XML editor (i.e., XMLSpy® or oXygen XML Editor) to start a new schema file in either the text view or graphic view interface. Define each element (including subelements, if any) with a name and annotation (for definition), and specify mandatory/optional conditions and cardinalities (number of occurrences). Upon completion, make sure to save the file in .xsd format.

2. Choose an album to create an XML record using the schema you created for Exercise 1. To start a new XML file, select File --> New in the XML software you installed in your computer. When you are prompted for a schema, select the schema file and start entering data. This time, make sure to save the file in .xml format.

3. When an album contains multiple tracks of songs, some songs may have different composers, arrangers, lyricists, and performers. Do you think the schema you created for Exercise 1 will be sufficient for describing the albums with multiple tracks and multiple creators, contributors, and performers? If not, how will you modify your XML schema to meet the description needs? In either case (modified or not) briefly explain your rationale for either a modification or making no changes.

4. Revise (as necessary) the XML schema you created for Exercise 1 based on your analysis in Exercise 3 to accommodate description needs for albums with multiple tracks, multiple creators, contributors, and performers. Either way, in the “revised” XML schema you will need to incorporate at least two elements from the DC namespace and create a namespace for your home-grown elements which will include both those from Exercise 1 and (if applicable) any new elements in the revised version. Make sure to save the new version in .xsd format, with clearly marked version number.

5. Create an XML record for an album using the XML schema from Exercise 4. The album must have multiple tracks and multiple composers, arrangers, lyricists, and performers.

Option 2

Option 2. Create an XML Schema for Chapter 3 exercise

Create an XML Schema for the element set you developed in the Chapter 3 exercise. In addition: apply the schema to create two records for two items you used in the Chapter 3 exercise.