MIME-version: 1.0
Content-Type: multipart/related;
	boundary="----=_NextPart_000_0076_01C29953.BE473C30";
	type="text/html"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106

This is a multi-part message in MIME format.

------=_NextPart_000_0076_01C29953.BE473C30
Content-Type: text/html; 
Content-Transfer-Encoding: quoted-printable
Content-Location: file:///D:/shint/homepage/2013-09/parseXML/index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
=20  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
=20<html xmlns=3D"http://www.w3.org/1999/xhtml">
=20<head>
=20<title>Parsing XML Responses with the W3C DOM</title>
=20    
=20<script type=3D"text/javascript">
=20var xmlHttp;
=20var requestType =3D "";
=20function createXMLHttpRequest() {
=20    if (window.ActiveXObject) {
=20        xmlHttp =3D new ActiveXObject("Microsoft.XMLHTTP");
=20    } 
=20    else if (window.XMLHttpRequest) {
=20        xmlHttp =3D new XMLHttpRequest();
=20    }
=20}
=20    
=20function startRequest(requestedList) {
=20    requestType =3D requestedList;
=20    createXMLHttpRequest();
=20    xmlHttp.onreadystatechange =3D handleStateChange;
=20    xmlHttp.open("GET", "parseXML.xml", true);
=20    xmlHttp.send(null);
=20}
=20    
=20function handleStateChange() {
=20    if(xmlHttp.readyState =3D=3D 4) {
=20        if(xmlHttp.status =3D=3D 200) {
=20            if(requestType =3D=3D "north") {
=20                listNorthStates();
=20            }
=20            else if(requestType =3D=3D "all") {
=20                listAllStates();
=20            }
=20        }
=20    }
=20}
=20 
=20function listNorthStates() {
=20 var xmlDoc =3D xmlHttp.responseXML;
=20 var northNode =3D xmlDoc.getElementsByTagName("north")[0];
=20   
=20    var northStates =3D northNode.getElementsByTagName("state");
=20    
=20    outputList("Northern States", northStates);
=20}
=20function listAllStates() {
=20    var xmlDoc =3D xmlHttp.responseXML;
=20 var allStates =3D xmlDoc.getElementsByTagName("state");
=20    
=20    outputList("All States in Document", allStates);
=20}
=20function outputList(title, states) {
=20    var out =3D title;
=20    var currentState =3D null;
=20    for(var i =3D 0; i < states.length; i++) {
=20        currentState =3D states[i];
=20        out =3D out + "\n- " + currentState.childNodes[0].nodeValue;
=20    }
=20    
=20    alert(out);
=20}
=20</script>
=20</head>
=20<body>
=20    <h1>Process XML Document of U.S. States</h1>
=20    <br/><br/>
=20    <form action=3D"#">
=20        <input type=3D"button" value=3D"View All Listed States" onclick=3D"startRequest('all');"/>
=20        <br/><br/>
=20        <input type=3D"button" value=3D"View All Listed Northern States" onclick=3D"startRequest('north');"/>
=20    </form>
=20</body>
=20</html>
=20

