Comunidad de diseño web y desarrollo en internet online

Valores XML en Array

Citar            
MensajeEscrito el 18 Jun 2006 11:30 pm
Hola a todos, estoy intentando recoger valores desde un XML y hasta ahí todo bién, pero me encuentro con un problema (a simple vista fácil) a la hora utilizar los datos recogidos en un array... no he encontrado forma de hacerlo:

Código :

News = new Array();

miXML = new XML();
miXML.ignoreWhite = 1; 
miXML.load("noticias.xml")
miXML.onLoad=cargaXML

function cargaXML(){
total=this.firstChild.childNodes.length;
for(i=0;i<=total-1;i++){
   News[i]= miXML.firstChild.childNodes[i].attributes.titulo;
   } 
}
textXML.text = News[0] //<---- Me da UNDEFINED


Cuando intento recuperar un valor del array, me da UNDEFINED una vez estoy fuera de la función.

Gracias de antemano...

Por netelbcn

1 de clabLevel



 

msie
Citar            
MensajeEscrito el 19 Jun 2006 02:39 am
mmmm, pues deberia funcionar, yo pondria esto:

Código :

var News:Array = new Array();
function cargaXML(){
for(i=0;i<=this.firstChild.childNodes.length;i++){
   News.push(miXML.firstChild.childNodes[i].attributes.titulo);
   } 
}
textXML.text = News[0];

Por bipsa

628 de clabLevel

1 tutorial
1 articulo

Genero:Masculino  

Colombia

firefox
Citar            
MensajeEscrito el 19 Jun 2006 06:54 am
Nada, seguimos igual... no lo entiendo!

Por netelbcn

1 de clabLevel



 

msie
Citar            
MensajeEscrito el 19 Jun 2006 09:39 am
Hola!!

Prueba de esta forma y ya me contaras:

Código :

var miXML= new XML();
miXML.ignoreWhite = true;
miXML.load("noticias.xml");

miXML.onLoad = function(exito) {
   if (exito) {
      var News:Array = new Array();
      total=this.firstChild.childNodes.length;
      for(i=0;i<=total-1;i++){
      News[i]= miXML.firstChild.childNodes[i].attributes.titulo;
      cargadoXML(News);
      
      }
   } else {
      trace("no cargó")
   }
   
};
function cargadoXML(News:Array){
textXML.text = News[0] //<---- Me da UNDEFINED
}



El XML sería de esta forma:

Código :

<Texto>
     <texto1 titulo= "Titulo del Texto 1" > </texto1>
     <texto2 titulo= "Titulo del Texto 2" > </texto2>
</Texto>

Por portavoz

23 de clabLevel



Genero:Masculino  

Galicia

msie
Citar            
MensajeEscrito el 19 Jun 2006 10:57 am
Perfecto, así si que puedo recogerlo sin problema!
Muchas gracias.

Por netelbcn

1 de clabLevel



 

msie
Citar            
MensajeEscrito el 22 Oct 2008 02:22 pm
Muchas gracias necesite algo parecido y me sirvio muy bien, muchas gracias. :cool:

Por lasg125

7 de clabLevel



 

Colombia

firefox
Citar            
MensajeEscrito el 07 Jul 2009 02:11 pm
He tenido un porblema similar y lo he solucionado utilizando "push" para ingresar los valores en el array. Mi codigo ha quedado algo asi:

Código ActionScript :

var lectorXML:XML = new XML();
conexXML.ignoreWhite = true;
lectorXML.onLoad = function(exito) {
   if (exito) {
      var item:Array = new Array();
      var cantidad:Number = new Number();
      cantidad = lectorXML.firstChild.childNodes.length;
      for (x=0; x<cantidad; x++) {
         item.push(lectorXML.firstChild.childNodes[x].firstChild.nodeValue);
      }
      trace(cantidad);
      trace(item);
   }
};
lectorXML.load("info_obras.xml");
stop();


El documento xml tiene esta estructura:

Código XML :

<?xml version="1.0" encoding="iso-8859-1"?>
    <info>
      <id>11</id>
      <id>24</id>
      <id>25</id>
      <id>26</id>
      <id>27</id>
    </info>

Gracias a todos los que postean las preguntas y las respuestas! por cierto este es mi primer post en Cristalab y para ser honesto debo decir que, si bien no soy un experto en flash, gran parte de mis conocimientos vienen de este sitio.

Por otsugua

1 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.