Hice unas pruebas y el archivo se lee, los loops funcionan, pero cuando pretendo ponerlo en una lista no me anda, muestra solo la primer imagen. Pienzo que el problema está en la parte comentada que pretende realizar una galeria de imagenes. Bueno quizas le sirva a alguien, saludos.
Código Javascript :
<script type="text/javascript"> 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","galeria.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML; var g=xmlDoc.getElementsByTagName("galeria"); for (h=0;h<g.length;h++) { document.write("<br>Galeria "+(h+1)+"de"+g.length);//prueva document.write('<h2>'); var nom=xmlDoc.getElementsByTagName("galeria")[h].getAttribute("rel"); document.write(nom); document.write('</h2>'); document.write('<ul class="gallery">'); var s=xmlDoc.getElementsByTagName("galeria")[h].getElementsByTagName("foto"); document.write("Cantidad de fotos de la galeria"+h+": "+s.length+"<br> Nombre: "+nom);//prueva for (i=0;i<s.length;i++) { document.write("<br> foto "+i+"<br> H: "+h+"<br>");//prueva var f =xmlDoc.getElementsByTagName("galeria")[h].getElementsByTagName("<br> foto ")[i]; /* document.write('<li><a href="'); document.write(f.getElementsByTagName("href")[i].childNodes[0].nodeValue); document.write('" rel="prettyPhoto['); document.write(nom); document.write(']" title="'); document.write(f.getElementsByTagName("titulo")[i].childNodes[0].nodeValue); document.write('"><img src="'); document.write(f.getElementsByTagName("src")[i].childNodes[0].nodeValue); document.write('" width="60" height="60" alt="'); document.write(f.getElementsByTagName("alt")[i].childNodes[0].nodeValue); document.write('" /></a></li>'); */ } //document.write("</ul>"); } </script>
Código XML :
?xml version="1.0" encoding="utf-8"?> <data> <galeria rel="Autos"> <foto id="50df6acb38f05"> <src>pics/thumb_50df7a07dad46.jpg</src> <href>pics/50df7a07dad46.jpg</href> <titulo>Clio</titulo> <alt>abc</alt> </foto> <foto id="50df7283b3056"> <src>pics/thumb_50df74b2e29fe.jpg</src> <href>pics/50df74b2e29fe.jpg</href> <titulo>Palio</titulo> <alt>un palio</alt> </foto> </galeria> <galeria rel="Electrónica"> <foto id="50df4d6e75037"> <src>pics/thumb_50df4d661c461.jpg</src> <href>pics/50df4d661c461.jpg</href> <titulo>Notebook</titulo> <alt>abc</alt> </foto> </galeria> <galeria rel="Varios"> <foto id="50df6bb8e3fb7"> <src>pics/thumb_50df6bab87c14.jpg</src> <href>pics/50df6bab87c14.jpg</href> <titulo>Zapatilla</titulo> <alt>z</alt> </foto> </galeria> </data>