Complete the following activities for practice with the eXtensible Markup Language (XML).

Syntax

Identify the two XML errors in each of the following examples and correct them. (solutions)

  1. <?xml version="1.0"?>
    
    <bookstore>
      <book category="CHILDREN">
        <title>Harry Potter</title>
        <Author>J K. Rowling</author>
        <year>2005</year>
        <price>29.99</price>
      </book>
      <book category=WEB>
        <title>Learning XML</title>
        <author>Eric T. Ray</author>
        <year>2003</year>
        <price>39.95</price>
      </book>
    </bookstore>
    
    1. Element names are case sensitive – <Author> should be <author>
    2. Attribute values must be quoted – category="WEB"
  2. <?xml version="1.0"?>
    
    <book category="CHILDREN">
      <title>Harry Potter</title>
      <author>J K. Rowling</author>
      <year>2005</year>
      <price>29.99</price>
    </book>
    <book category="WEB">
      <title>Learning XML</title>
      <author>Eric T. Ray & John S. Green</author>
      <year>2003</year>
      <price>39.95</price>
    </book>
    
    1. XML documents must have a single root element
    2. XML entities (i.e., &) must be escaped – &amp;
  3. <?xml version="1.0"?>
    
    <bookstore>
    <book category="CHILDREN">
      <title>Harry Potter</title>
      <author>J K. Rowling</author>
      <year>2005<month>August</year></month>
      <price>29.99</price>
    </bookstore>
    
    1. XML tags must be closed – missing </book> before </bookstore>
    2. XML tags must be nested correctly – close year tag before month

Design

Design an XML document to track a triathlon race. Racers have a number, first name, last name, and race times for swimming, biking, and running.