<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
</CATALOG>
Este é o meu codigocódigo XML e de seguida coloco o meu htmlHTML.
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
th,
td {
padding: 5px;
}
</style>
</head>
<body>
<script>
if (window.XMLHttpRequest)
{ // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new xmlhttp = new XMLHttpRequest();
}
else
{ // code for IE6, IE5
xmlhttp=new xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "contactos.xml", false);
xmlhttp.send();
xmlDoc=xmlhttp xmlDoc = xmlhttp.responseXML;
document.write("<table><tr><th>Artist</th><th>Title</th></tr>");
var x=xmlDocx = xmlDoc.getElementsByTagName("CD");
for (i=0;i<xi = 0; i < x.length;i++length; i++)
{ {
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>
Problema:
Eu
Eu abro a página e ela vem em branco.
É a primeira vez que estou a fazer ou a tentar fazer uma pagina com XML.