Site hosted by Angelfire.com: Build your free website today!

XML ja HTML

xml.jpg

XML dokumendis asetsevat datat on võimalik kuvada ka HTML'i abil.

Allpool olevas näites kuvame XML faili eu.xml nii, et faili elemendid paigutuvad tabelisse:

<html>
<body>

<script type="text/javascript">

var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load("http://pyramdesign.angelfire.com/xml/nai/eu.xml");

document.write("<table border='1'>");

var x=xmlDoc.getElementsByTagName("LOETELU");
for (i=0;i<x.length;i++)
{ 
document.write("<tr>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("RIIK")[0].childNodes[0].nodeValue);
document.write("</td>");

document.write("<td>");
document.write(
x[i].getElementsByTagName("PEALINN")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>

</body>
</html>

Mida me siis tegime?

Proovi ise

Selleks, et paremini tundma õppida seda teemat siis tutvu lähemalt
XML DOM materjalidega.





Punane Nool Vasak Punane Nool