1. (50 points) The holiday tree shown to right is a 300x300 pixel image used as the background-image for the table cell. In the cell is a DIV block with id="tdiv". There is a button labelled "p1" that executes a javascript function named p1. There is also a textbox where the user can enter then number of ornaments to be placed on the tree. This textbox is named numo and is in a form named p1f. In the function p1 there is a seven element array named b that contains the HTML text to display seven ornament image files ( b(0)="<img src='ylball.gif' height='15'>"; b(1)="<img src='blball.gif' height='15'>";...b(6)="<img src='mgball.gif' height='15'>" ). When the user clicks the "p1" button, the function retrieves the value of numo from the textbox. The function will then use a while (condition) loop to: generate (1,2, and 3 below), test (4 below), place and count (5 below) numo ornaments (span blocks with image tags inside) into a single "output string". [Note: the "while" loop continues until the number of ornaments is equal to numo]:
|
|
|
<xml id="census_2009"> <?xml version="1.0"?> <!DOCTYPE census [ <!ELEMENT census (state+)> <!ELEMENT state (state_name,county+)> <!ELEMENT state_name (#PCDATA)> <!ELEMENT county (county_name,population)> <!ELEMENT county_name (#PCDATA)> <!ELEMENT population (#PCDATA)> ]> <census> <state><state_name>Alabama</state_name> <county><county_name>Autauga County</county_name> <population>43671</population></county> <county><county_name>Baldwin County</county_name> <population>140415</population></county> <county><county_name>Barbour County</county_name> <population>29038</population></county> <county><county_name>Bibb County</county_name> <population>20826</population></county> ...lotsa lines omitted... <county><county_name>Teton County</county_name> <population>18251</population></county> <county><county_name>Uinta County</county_name> <population>19742</population></county> <county><county_name>Washakie County</county_name> <population>8289</population></county> <county><county_name>Weston County</county_name> <population>6644</population></county> </state></census></XML> |
2. (50 points) The XML for the 2009 census population estimates for states and their counties are shown to the left . The DTD states that the census population estimates are arranged by states, then by county. The XML is in an IE XML container with id="census_2009". Write a javascript function named p2, that is executed by clicking this button:
This function processes the census XML to produces a page-on-the-fly with: a 51 row, 3 column table shown below that contains: (a) the state name in the first column; (b) the number of counties in the state in the second column;(c) the total state population in the third column found by summing up all the state's county populations. Further, show: (d) the total population of the census; (e) the state with the maximum population and its population; and (f) the county with the maximum population, its name, and its state. The output looks like this:
(e) Maximum State Population=33871648 in California (f) Maximum County Population=9519338 in Los Angeles County in California root.childNodes(i).childNodes(0).text is the state name for state i for (j=1;j<root.childNodes(i).childNodes.length;j++) is the loop for the counties root.childNodes(i).childNodes(j).childNodes(0).text is the county name root.childNodes(i).childNodes(j).childNodes(1).text is the county population Show only the javascript for p2. Show NO HTML. |