XML
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)
-
<?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>
- Element names are case sensitive –
<Author>
should be<author>
- Attribute values must be quoted –
category="WEB"
- Element names are case sensitive –
-
<?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>
- XML documents must have a single root element
- XML entities (i.e.,
&
) must be escaped –&
-
<?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>
- XML tags must be closed – missing
</book>
before</bookstore>
- XML tags must be nested correctly – close
year
tag beforemonth
- XML tags must be closed – missing
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.