This is the HTML code, file name Breakfast_menu. HTML:
XML file for a node under certain elements & lt;/title>
<meta charset="utf-8" & gt;
<script>
If (window. The XMLHttpRequest) {
//code for IE7 +, Firefox, Chrome, Opera, Safari
XMLHTTP=new XMLHttpRequest ();
}
The else {
//code for IE6, IE5
XMLHTTP=new ActiveXObject (" Microsoft. XMLHTTP ");
}
XMLHTTP. Open (" GET ", "Breakfast_menu. XML", false);
XMLHTTP. The send ();
XmlDoc=XMLHTTP. ResponseXML;
X=xmlDoc. GetElementsByTagName (" food ");//x forget wrote
The function displayFood (I) {
Name=(x [I] getElementsByTagName (" name ") [0]..childnodes [0]. The nodeValue);
Price=(x [I] getElementsByTagName (" price "). [0].childnodes [0]. The nodeValue);
Description=(x [I] getElementsByTagName (" description "). [0].childnodes [0]. The nodeValue);
Calories=(x [I] getElementsByTagName (" calories ") [0]..childnodes [0]. The nodeValue);
TXT="I:" + I + "& lt; Br/& gt; Name: "+ Name +" & lt; Br/& gt; Price: "+ Price +
"& lt; Br/& gt; Description: "+ Description +" & lt; Br/& gt; Calories: "+ Calories;
Document. The getElementById (" showFood "). The innerHTML=TXT;//is getElementById (), not getElementsById (), no s,
}
</script>
<body>
<script>
Document. Write (" & lt; The table border='1' ");
//traverse every food
For (var I=0; i Document. Write (" & lt; Tr onclick=displayFood (" + I + ") & gt;" );
Document. Write (" & lt; Td>" );
Document. The write (I);
Document. Write (" & lt;/td> " ); Document. The write (x [I] getElementsByTagName (" name ") [0]..childnodes [0]. The nodeValue); Document. Write (" & lt;/td> | " ); Document. The write (x [I] getElementsByTagName (" price ") [0]..childnodes [0]. The nodeValue); Document. Write (" & lt;/td> " ); } Document. Write (" & lt;/table>" ); Document. The write (" params. Length: "+ x.l ength);
</script>
|