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", "note.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
document.write("<table border='1'>");
document.write("<tr><td><b>标题:</B></td><td>");
document.write(xmlDoc.getElementsByTagName("heading")[0].childNodes[0].nodeValue)
document.write("</td></tr>");
document.write("<tr><td>接受者:</td><td>");
document.write(xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue)
document.write("</td></tr>");
document.write("<tr><td>来自:</td><td>");
document.write(xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue)
document.write("</td></tr>");
document.write("<tr><td>内容:</td><td>");
document.write(xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue)
document.write("</td></tr>");
document.write("</table>");
note.xml
<?xml version="1.0" encoding="iso-8859-1" ?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>