Using image and CSS class tags in XML output?



I hope this makes sense - sorry I'm a bit new to all this! So right now I am working on a simple HTML page for work. It includes a section with links to featured videos. This is the only section that needs to be updated by staff members. For each of these videos there is an image, title and description.


As my manager is unlikely to want to mess around with the complete HTML page, I had the idea of pulling in a simple XML file, containing just the values for the three attributes that need to be updated.


I have tried to include this XML file in the HTML page, but have noticed that it doesn't output anything if img, css or a tags are used to wrap around these values.


Here is my HTML:



<div id="video_div_row">

<script>
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","videos.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

var x=xmlDoc.getElementsByTagName("FEATUREDLAP");
for (i=0;i<x.length;i++)
{
document.write("<div class="video">");
document.write("<div class="video_img"><img src="");
document.write(x[i].getElementsByTagName("IMAGE")[0].childNodes[0].nodeValue);
document.write("" width="163" height="110"></div>");
document.write("<h2><a href="#">s");
document.write(x[i].getElementsByTagName("RACER")[0].childNodes[0].nodeValue);
document.write("</a></h2><p>");
document.write(x[i].getElementsByTagName("DESCRIPTION")[0].childNodes[0].nodeValue);
document.write("</p></div>");
}
</script>

</div>


Here is my XML:



<?xml version="1.0" encoding="UTF-8"?>

<VIDEOS>

<FEATUREDLAP>
<IMAGE>lap_img.png</IMAGE>
<RACER>Brian</RACER>
<DESCRIPTION>Lap description sample...</DESCRIPTION>
</FEATUREDLAP>

</VIDEOS>


Does anyone have any suggestions on how I can tweak the code to make this work? Or can you recommend an alternative way of implementing this simple idea?


Thank you!


No comments:

Post a Comment