I'm having trouble with some XML DOM. (Never really used it before, but I thought I'd take a shot.) - I'm using it for my portfolio (and other pages with content.) on my site, linking thumbnails with their links, titles, descriptions etc.
Anyway, I'm not exactly sure what the problem is, but it doesn't work. /:
.js
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send();
return xhttp.responseXML;
}
function imageList(value)
{
xmlDoc=loadXMLDoc("uploads.xml");
x=xmlDoc.getElementsByTagName(value)[0].childNodes;
for (i=0;i<x.length;i++)
{
document.write("<h1>"+x[i].getAttribute('id')+"</h1>");
document.write("<ul style='list-style-type: none;'>");
y=x[i].childNodes;
for(j=0;j<y.length;j++)
{
document.write("<li style='background: url("+y[j].getAttribute('thumbnail')+") no-repeat center center;'><a href='#'></a></li>");
}
document.write("</ul>");
}
}
.html
<html>
<head>
<script type="text/javascript" src="js/xmldata.js"></script>
</head>
<body>
<script>
imageList("portfolio");
</script>
</body>
</html>
.xml
<?xml version="1.0" encoding="UTF-8"?>
<portfolio>
<year id="2014">
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
</year>
<year id="2013">
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
</year>
<year id="2012">
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
</year>
<year id="2011">
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
<image thumbnail="" href="" desc=""></image>
</year>
</portfolio>