XML HTML DATA

We can generate a web page with information from an XML file

If we have this file on our server "mensajes.xml"

<?xml version="1.0" encoding="UTF-8"?> <messages>      <message>          <to>John</to>          <from>Peter</from>          <title>Meeting</title>          <text>Remember out meeting</text>     </message>     <message>          <to>Patrick</to>          <from>Ray</from>          <title>Contract</title>          <text>Send me the contract</text>     </message>     <message>          <to>Stephan</to>          <from>Thomas</from>          <title>Date</title>          <text>Remember out date</text>     </message>     <message>          <to>William</to>          <from>James</from>          <title>Tennis</title>          <text>Tomorrow we play tennis</text>     </message>     <message>          <to>Michael</to>          <from>Paul</from>          <title>Trip</title>          <text>Send me the trip plan</text>     </message> </messages>

The following website (mensajes.htm) is generated by using JAVASCRIPT data from the XML file above.

<html> <body> <script type="text/javascript"> if (window.XMLHttpRequest) {     xmlhttp=new XMLHttpRequest(); } else {     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","mensajes.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("message"); for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x[i].getElementsByTagName("to")[0].childNodes[0].nodeValue); document.write("</td><td>"); document.write(x[i].getElementsByTagName("from")[0].childNodes[0].nodeValue); document.write("</td></tr>"); document.write("<tr><td>"); document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue); document.write("</td><td>"); document.write(x[i].getElementsByTagName("text")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } document.write("</table>"); </script> </body> </html>