简体   繁体   中英

Displaying Image from XML into HTML

I have tried to display the following image onto the html, however to no avail. When the html is loaded, it displays the picture icon, but it won't display the image itself. I have copied the code below

Thanks.

HTML Code:

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

document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("TEST");
for (i=0;i<x.length;i++)
{
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
var img = document.createElement("img");
img.src = x[i].getElementsByTagName("imageurl")[0].childNodes[0].nodeValue;
document.write(img.src);
document.body.appendChild(img);
}
document.write("</table>");


</script>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<TEST_GROUP>
    <TEST>
        <TITLE>Hello World</TITLE>
        <imageurl>"CFL_175x175.png"</imageurl>
    </TEST>

</TEST_GROUP>

尝试这个:

<imageurl>CFL_175x175.png</imageurl>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM