html文件: <html> <head> <script type="text/javascript"> function parseXML() { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","class.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; xmlDoc.async=false; var val=xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue; alert(val); } </script> </head> <body onload="parseXML()"> </body> </html> class.xml <?xml version="1.0" encoding="utf-8"?> <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note> |
|