Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/09/2011, 02:26
paskuini
 
Fecha de Ingreso: junio-2009
Mensajes: 156
Antigüedad: 15 años, 8 meses
Puntos: 7
Seleccionar elemento hijo de un documento xml / seleccionar hijo con javascript

Necesito ayuda con esto que ahora os cuento.
Tengo un documento xml con la siguiente estructura:
Código PHP:
<CATALOGO>
    <
CATEGORIA>
        <
SUBCATEGORIA>
            <
PRODUCTOS>
                <
PRODUCTO1>
                    <
NOMBRE>Producto1</NOMBRE>
                    <
DESCRIPCION>Esto es una prueba de xml</DESCRIPCION>
                    <
QUOTE>Probando xml</QUOTE>
                    <
FOTO1>../img/p1.jpg</FOTO1>
                    <
FOTO2>../img/p2.jpg</FOTO2>
                    <
FOTO3>../img/p3.jpg</FOTO3>
                    <
FOTO4>../img/p4.jpg</FOTO4>
                    <
FOTO5>../img/p5.jpg</FOTO5>
                    <
FOTO6>../img/p6.jpg</FOTO6>
                </
PRODUCTO1>
                <
PRODUCTO2>
                    <
NOMBRE>Producto2</NOMBRE>
                    <
DESCRIPCION>Esto es una prueba de xml</DESCRIPCION>
                    <
QUOTE>Probando xml</QUOTE>
                    <
FOTO1>../img/p1.jpg</FOTO1>
                    <
FOTO2>../img/p2.jpg</FOTO2>
                    <
FOTO3>../img/p3.jpg</FOTO3>
                    <
FOTO4>../img/p4.jpg</FOTO4>
                    <
FOTO5>../img/p5.jpg</FOTO5>
                    <
FOTO6>../img/p6.jpg</FOTO6>
                </
PRODUCTO2>
            </
PRODUCTOS>
        </
SUBCATEGORIA>
        <
SUBCATEGORIA>
            <
PRODUCTOS>
                <
PRODUCTO1>
                    <
NOMBRE>Prueba PRODUCTOSs 2</NOMBRE>
                    <
DESCRIPCION>Esto es una prueba de xml</DESCRIPCION>
                    <
QUOTE>Probando xml</QUOTE>
                    <
FOTO1>../img/p1.jpg</FOTO1>
                    <
FOTO2>../img/p2.jpg</FOTO2>
                    <
FOTO3>../img/p3.jpg</FOTO3>
                    <
FOTO4>../img/p4.jpg</FOTO4>
                    <
FOTO5>../img/p5.jpg</FOTO5>
                    <
FOTO6>../img/p6.jpg</FOTO6>
                </
PRODUCTO1>
            </
PRODUCTOS>
        </
SUBCATEGORIA>
    </
CATEGORIA>
</
CATALOGO
y un documento html con la siguiente:
Código PHP:
<html>
    <
head>
        <
style>
            
body{font-family:VerdanaGenevasans-serif;}
            
h1{font-size:2em;}
            
h2{font-size:1.5em;}
            
h3{font-size:1em;}
            
img{padding:5px;}
        </
style>
    </
head>
    <
body>
    
    <
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","productos.xml",false);
        
xmlhttp.send();
        
xmlDoc=xmlhttp.responseXML;
        
        var 
x=xmlDoc.getElementsByTagName("PRODUCTOS");
        for (
i=0;i<x.length;i++)
          {
          
document.write("<h1>");
          
document.write(x[i].getElementsByTagName("NOMBRE")[0].childNodes[0].nodeValue);
          
document.write("<h1><h2>");
          
document.write(x[i].getElementsByTagName("DESCRIPCION")[0].childNodes[0].nodeValue);
          
document.write("</h2><h3>");
          
document.write(x[i].getElementsByTagName("QUOTE")[0].childNodes[0].nodeValue);
          
document.write("</h3><img src='");
          
document.write(x[i].getElementsByTagName("FOTO1")[0].childNodes[0].nodeValue);
          
document.write("'/><img src='");
          
document.write(x[i].getElementsByTagName("FOTO2")[0].childNodes[0].nodeValue);
          
document.write("'/><img src='");
          
document.write(x[i].getElementsByTagName("FOTO3")[0].childNodes[0].nodeValue);
          
document.write("'/><img src='");
          
document.write(x[i].getElementsByTagName("FOTO4")[0].childNodes[0].nodeValue);
          
document.write("'/><img src='");
          
document.write(x[i].getElementsByTagName("FOTO5")[0].childNodes[0].nodeValue);
          
document.write("'/><img src='");
          
document.write(x[i].getElementsByTagName("FOTO6")[0].childNodes[0].nodeValue);
          
document.write("'/>");
          }
    
</script>
    
    </body>
</html> 
el script que tengo me muestra los artículos dentro de <PRODUCTOS>; pero yo quiero que me muestre los HIJOS de la etiqueta <PRODUCTOS>.
¿Cómo selecciono el elemento hijo con javascript?