Introduction to XML: Workshop Exercises

These exercises will help ensure that you understand all the syntax discussed in class. You should work all the exercises in writing, even the ones to which the answer is obvious. After you have had an opportunity to work the problems in a particular exercise, the instructor will go over the solutions to the exercises. In some cases, there may be alternate solutions that are also correct. If the instructor's answer is different than yours, be sure to inquire about it, as it may be that your answer is also technically correct.

Exercise #1 – Information Structure

In this exercise, you will practice identifying the structure of an information object. For the sample document provided below:

 

  1. Label the information structures you see, including containing structures.
  2. Draw a tree representation of the structure.


Exercise #2 – Deconstructing an XML Document

In this exercise, you will practice identifying the explicit structure within an XML document. In a sense, this is the reverse of what you did in Exercise #1. For the sample XML markup below, create a document-like representation (or a simple drawing) for the content contained within the XML tags:

 

 

<book>

<coverInfo>

      <title>The XML Handbook</title>

      <author>Charles F. Goldfarb</author>

      <author>Paul Prescod</author>

      <edition>Second</edition>

<description>The definitive XML resource: applications, products, and technologies. Revised and expanded—over 600 new pages.

</description>

</coverInfo>

</book>

 


Exercise #3 – Creating XML Markup

In this exercise, create some XML markup based on the tree representation from Exercise #1 above, and the content from the original sample document.

 

 

 

 

 

 

 

 

 

 

 

 

 

Exercise #4 – Well-Formedness

This exercise checks your understanding of the constraints for well-formedness. Are the following document instances well-formed? Explain any NO answers.

 

<list><title>The first list</title><item>An item</list>

 

 

<item>An item</item><item>Another item</item>

 

 

<para>Bathing a cat is a <emph>relatively</emph> easy task as long as the cat is willing.</para>

 

 

<bibl><title>How to Bathe a Cat<author></title>Merlin Bauer<author></bibl>


Exercise #5 – Well Formedness

This exercise is a bit more challenging than the previous example. Here is a fragment of an XML document instance. Identify all the places where it fails to match the constraints for well-formedness. If you can’t remember all of the rules, consult the powerpoint slide handouts included in your workshop folder.

 

<PROCEDURE><TITLEHow to Bathe a Cat</TITLE><OVERVIEW>This procedure

tells you how to bathe a cat. <WARNING></OVERVIEW>Cats don't like to take baths. You could get hurt doing this. Be sure to obtain all the required protective gear before you start. </WARNING><EQUIPEMENT><ITEM>Hockey Mask <ITEM>Padded Full-body Kevlar Armor</ITEM><ITEM>Tub full of warm water</ITEM><ITEM>Towels </ITEM><ITEM>First Aid kit</ITEM><ITEM>Cat Shampoo</ITEM> <EQUIPMENT><INSTRUCTIONS> <STEP> Locate the cat, who by now is hiding under the bed.</STEP><STEP>Place the cat in the tub of water.</STEP> <ITEM>Using the First Aid kit, repair the damage to your head and arms.</STEP> <STEP>Place the cat back in the tub and hold it down.</STEP> <STEP>Wash it really fast, then make an effort to dry it with the towels.</STEP> <STEP>Decide not to do this again. </STEP> </INSTRUCTIONS>