Chapter Assignments


Home

Section 14.1 Which of the following are valid XML element names? (Select all that apply.)

1. yearBorn
Answer: Correct

2. year.Born
Answer: Correct

3. year Born
Answer: incorrect because it contains a space

4. year-Born1
Answer: Correct

5. 2_year_born
Answer: incorrect because the first character is a number.

6. _year_born_
Answer: Correct


Section 14.2 State which of the following statements are true and which are false. If false, explain why.

1. XML is a technology for creating markup languages.
Answer: True

2. XML markup is delimited by forward and backward slashes (/ and \).
Answer: False. In an XML document, markup text is delimited by tags enclosed in angle brackets (< and >) with a forward slash just after the < in the end tag.

3. All XML start tags must have corresponding end tags.
Answer: True

4. Parsers check an XML document’s syntax.
Answer: True

5. XML does not support namespaces.
Answer: False. XML does support namespaces.

6. When creating XML elements, document authors must use the set of XML tags provided by the W3C.
Answer: False. When creating tags, document authors can use any valid name but should avoid ones that begin with the reserved word xml (also XML, Xml, etc.).

7. The pound character (#), dollar sign ($), ampersand (&) and angle brackets (< and >) are examples of XML reserved characters.
Answer: False. XML reserved characters include the ampersand (&), the left angle bracket (<) and the right angle bracket (>), but not # and $.

8. XML is not case sensitive.
Answer: False. XML is case sensitive.

9. XML Schemas are better than DTDs, because DTDs lack a way of indicating what specific type of data (e.g., numeric, text) an element can contain and DTDs are not themselves XML documents.
Answer: True

10. DTDs are written using an XML vocabulary.
Answer: False. DTDs use EBNF grammar, which is not XML syntax.

11. Schema is a technology for locating information in an XML document.
Answer: False. XPath is a technology for locating information in an XML document. XML Schema provides a means for type checking XML documents and verifying their validity.


Section 14.3 Fill in the blanks for each of the following

1. __________ help prevent naming collisions.
Answer: Namespaces.

2. __________ embed application-specific information into an XML document.
Answer: Processing instructions

3. __________ is Microsoft’s XML parser.
Answer: MSXML

4. XSL element __________ writes a DOCTYPE to the result tree.
Answer: xsl:output

5. XML Schema documents have root element __________.
Answer: schema

6. XSL element __________ is the root element in an XSL document.
Answer: xsl:stylesheet

7. XSL element __________ selects specific XML elements using repetition.
Answer: xsl:for-each

8. Nodes that contain other nodes are called __________ nodes.
Answer: parent

9. Nodes that are peers are called __________ nodes.
Answer: sibling


Section 14.4 Answer the following

In Fig. 14.2, we subdivided the author element into more detailed pieces. How might you subdivide the date element? Use the date May 5, 2005, as an example.
Answer:

        <date>
            <month>May</month>
            <day>5</day>
            <year>2005</year>
        </date>.
        


Section 14.5 Perform the following

Write a processing instruction that includes style sheet wap.xsl.
Answer:

<?xml-stylesheet type="text/xsl" href="wap.xsl" ?>


Section 14.6 Perform the following

Write an XPath expression that locates contact nodes in letter.xml (Fig. 14.4).
Answer: /letter/contact>


Section 14.7 Create an XML document for the following

(Nutrition Information XML Document) Create an XML document that marks up the nutrition facts for a package of Grandma White’s cookies. A package of cookies has a serving size of 1 package and the following nutritional value per serving: 260 calories, 100 fat calories, 11 grams of fat, 2 grams of saturated fat, 5 milligrams of cholesterol, 210 milligrams of sodium, 36 grams of total carbohydrates, 2 grams of fiber, 15 grams of sugars and 5 grams of protein. Name this document nutrition.xml. Load the XML document into Internet Explorer. [Hint: Your markup should contain elements describing the product name, serving size/amount, calories, sodium, cholesterol, proteins, etc. Mark up each nutrition fact/ingredient listed above.]
Answer: answer to 14.07


Section 14.8 Write an XML Schema document for the following

(Nutrition Information XML Schema) Write an XML Schema document (nutrition.xsd) specifying the structure of the XML document created in Exercise 14.7.
Answer: answer to 14.08


Section 14.9 Write an XSL style sheet for the following

(Nutrition Information XSL Style Sheet) Write an XSL style sheet for your solution to Exercise 14.7 that displays the nutritional facts in an XHTML table. Modify Fig. 14.38 to output the results.
Answer: answer to 14.09


Section 14.10 Perform the following

(Sorting XSLT Modification) Modify Fig. 14.23 (sorting.xsl) to sort by the number of pages rather than by chapter number. Save the modified document as sorting_byPage.xsl.
Answer: Not Required


Section 14.11 Perform the following

Modify Fig. 14.38 to use sorting.xml (Fig. 14.22), sorting.xsl (Fig. 14.23) and sorting_byPage.xsl (from Exercise 14.10). Display the result of transforming sorting.xml using each style sheet. [Hint: Remove the xml:stylesheet processing instruction from line 2 of sorting.xml before attempting to transform the file programmatically.]
Answer: Not Required