Chad Lawrence

Web Development for Tech Applications (TECH 64095-001)

clawre13@kent.edu

Chapter 14 - XML and RSS

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

  1. yearBorn Yes.
  2. year.Born Yes.
  3. year Born No. Incorrect because it contains a space.
  4. year-Born1 Yes.
  5. 2_year_born No. Incorrect because first character is a number.
  6. _year_born_ Yes.

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. True.
  2. XML markup is delimited by forward and backward slashes (/ and \). 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. True.
  4. Parsers check an XML document's syntax. True.
  5. XML does not support namespaces. False. XML does support namespaces.
  6. When creating XML elements, document authors must use the set of XML tags provided by the W3C. 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. 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. 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. True.
  10. DTDs are written using an XML vocabulary. False. DTDs use EBNF grammer, which is not XML syntax.
  11. Schema is a technology for locating information in an XML document. 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.

14.3 Fill in the blanks in each of the following:

  1. Namespaces help prevent naming collisions.
  2. Processing instructions embed application-specific information into an XML document.
  3. MSXML is Microsoft's XML parser.
  4. XSL element xsl:output writes a DOCTYPE to the result tree.
  5. XML Schema documents have root element schema.
  6. XSL element xsl:stylesheet is the root element in an XSL document.
  7. XSL element xsl:for-each selects specific XML elements using repetition.
  8. Nodes that contain other nodes are called parent nodes.
  9. Nodes that are peers are called sibling nodes.

14.4 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.

fig-14-2

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

14.5 Write a processing instruction that includes style sheet wap.xsl.

<xsl:stylesheet type = "text/xsl" href = "wap.xsl" />

14.6 Write an XPath expression that locates contact nodes in letter.xml (Fig. 14.4).

fig-14-4

fig-14-4

/letter/contact.

14.7 (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.]

14.7 Answer

14.8 (Nutrition Information XML Schema) Write an XML Schema document (nutrition.xsd) specifying the structure of the XML document created in Exercise 14.7.

14.8 Answer

14.9 (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.

fig-14-38

fig-14-38

fig-14-38

14.9 Answer

14.10 (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.

fig-14-23

fig-14-23

14.10 Answer

14.11 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 results 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.]

fig-14-22

(see question 14.10 for Fig. 14.23)

(see question 14.9 for Fig. 14.38)

14.11 Answer