HTML:
<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> new document </title>
<Meta name = "generator" content = "editplus">
<Meta name = "author" content = "">
<Meta name = "keywords" content = "">
<Meta name = "Description" content = "">
<SCRIPT type = "text/JavaScript" src = "XMLHttpRequest. js"> </SCRIPT>
</Head>
<Body>
<Div id = "see">
</Div>
<Input type = "button" onclick = "sendrequest ()" value = "sendrequest">
<SCRIPT>
VaR XMLHTTP = new XMLHttpRequest ();
VaR xmldoc;
Function sendrequest (){
Document. All ("see"). innerhtml = "loading ....";
VaR url = "http: // localhost: 8080/tree. xml ";
XMLHTTP. Open ("get", URL, true );
XMLHTTP. onreadystatechange = viewpage;
XMLHTTP. Send (null );
}
Function viewpage (){
If (XMLHTTP. readystate = 4 & XMLHTTP. Status = 200 ){
Alert ("Haha get XML ")
Xmldoc = XMLHTTP. responsexml;
VaR xmlobj = xmldoc.doc umentelement;
VaR STR = "";
For (VAR I = 0; I <xmlobj. childnodes. length; I ++ ){
VaR node = xmlobj. childnodes [I];
VaR text = node. getattribute ("nodeid ");
VaR value = text;
STR + = "<span style = 'display: Block' onclick = 'getsub (\" "+ value + "\") '> "+ TEXT +" </span> <br> <Div style = 'display: none' id = "+ TEXT +"> </div> ";
}
Document. all. See. innerhtml = STR;
// Alert (xmlobj. tagname)
}
}
Function getsub (ID ){
If (xmldoc! = NULL ){
VaR root = xmldoc. getelementsbytagname ("treenode ");
VaR str2 = "";
For (var k = 0; k <root. length; k ++ ){
If (root [K]. getattribute ("nodeid") = ID ){
Document. All (ID). style. Display = '';
Document. All (ID). innerhtml = "loading ..."
Alert ("Get sub Tree ")
VaR nodes = root [K]. childnodes;
For (VAR m = 0; m <nodes. length; m ++ ){
VaR node = nodes [m];
VaR text = node. getattribute ("nodeid ");
Str2 + = "<span onclick = 'getsub (\" "+ TEXT +" \ ") '> & nbsp; "+ TEXT +" </span> <br> <Div style = 'display: none' id = "+ TEXT +"> </div> ";
}
Document. All (ID). innerhtml = str2; // alert (document. All (ID). innerhtml)
}
}
} Else {
Alert ("Exception !! ");
}
}
</SCRIPT>
</Body>
</Html>
XML to be accessed: