Exercises

5.5 Create an XML document that marks up the nutrition facts for a package of Grandma Deitel's Cookies. A package of Grandma Deitel's 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.Render the XML documents in Internet Explorer 5. [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. Use nested elements as necessary.]

5.6 Markup the Java code listed in Fig. 5.12 using XML. Represent the if statement with element if—which contains one or more condition elements and one or more statement elements. Element condition contains the condition (e.g., m == month && d == day) and element statement contains the statements (e.g., resultDay = "DATE: D " + d + " M " + m). We have provided comments to the right of conditions and statements for easy identification. Element else represents an else statement in Java and contains one or more statement elements. Render the XML document in IE5.

5.7 Modify your solution to Exercise 5.5 by placing the Java code (Fig. 5.12) inside a CDATA section. Then render the document in IE5. Other than the syntax coloring, the Java code should be displayed exactly as shown in Fig. 5.12.

if ( ( m == month && d == day ) || ( month == -1 && d == day ) || ( m == month && day == -1 ) || ( month > -1 && day <= -1 ) ) { resultDay = "DATE: D " + d + " M processChildNodes(dateElement.getChildNodes());

else return;

// m == month && d == day // month == -1 && d == day // m == month && day == -1 // month > -1 && day <= -1 + m; // a statement a statement

// else statement // a statement

Fig. 5.12 Java code to markup.

xmlhtp1_05.fm Page 133 Friday, November 30, 2001 9:32 AM

xmlhtp1_05.fm Page 133 Friday, November 30, 2001 9:32 AM

Chapter 5

Creating Markup with XML 133

5.8 Rewrite the XML document in Fig. 5.10 such that each note element has year, month, day and time attributes rather than child elements. The solution should contain only the root element and note child elements.

5.9 Write a CSS stylesheet for Fig. 5.1 that results in the text Welcome to XML! being displayed in blue Times 20 pt.

0 0

Post a comment