Ver Mensaje Individual
  #3 (permalink)  
Antiguo 05/04/2008, 18:09
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Re: leer XMl conJAvaScript

Bueno, hay algunas cosas que están mal. Tu xml no tiene encabezados ni un nodo padre. Tendrías que convertirlo a un esquema semejante a este:
Código PHP:
<?xml version="1.0" encoding="iso-8859-1"?>
<r>
    <paper>
        <id>1</id>
        <titulo>titulo muy interesante</titulo>
    </paper>
    <paper>
        <id>2</id>
        <titulo>titulo no tan interesante</titulo>
    </paper>
</r>
Tampoco realizás bien el parseo. Fijate en este ejemplo:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>test</title>
<
script>
function 
ajax(){
    if(
window.XMLHttpRequest){
        return new 
XMLHttpRequest()
    }else{
        try{
            return new 
ActiveXObject('Microsoft.XMLHTTP');
        }catch(
e){
            
alert('nop');
            return;
        }
    }
}
aj=new ajax();
try{
aj.open('GET','test.xml',true);
aj.onreadystatechange=function(){
    if(
aj.readyState==4){
        
xml=aj.responseXML.getElementsByTagName('paper');
        for(
i=0;i<xml.length;i++){
            
alert(xml[i].getElementsByTagName('id')[0].firstChild.data);
            
alert(xml[i].getElementsByTagName('titulo')[0].firstChild.data);
        }
        
aj.onreadystatechange=null;
    }
}
aj.send(null);
}catch(
e){}
</script>
</head>

<body>
</body>
</html> 

Última edición por Panino5001; 05/04/2008 a las 18:15