xml getElementById

11 views
Skip to first unread message

Iván Gajate

unread,
Apr 12, 2010, 12:16:51 PM4/12/10
to asna...@googlegroups.com
Hola chicos
¿existe algo en E4X como getElementById?

Es que no conozco el nombre de la etiqueta, y molaría hacer algo como:

miXml..(@id == "contenido")

Yo me he hecho una función recursiva así:

function getElementById(data:XML, id:String):XML{
var element:XML;
loop(data);
function loop(branch:XML):void {
var l:uint = branch.elements().length();
for(var i:uint = 0; i < l; i++) {
var subBranch:XML = branch.elements()[i];
if(subBranch.@id == id){
element = subBranch;
return;
}
// si la rama tiene hijos lo hago recursivo
if (subBranch.hasComplexContent()) {
loop(subBranch);
}
}
}

return element;
}


que funciona bien, pero molaría mas lo otro :)
Gracias.

Joseba Alonso

unread,
Apr 13, 2010, 6:06:58 AM4/13/10
to asna...@googlegroups.com
MiXMl.descendents().(hasOwnProperty("@id") && @id == "contenido")[0]

Algo asi te debería de tirar


Joseba

Iván Gajate

unread,
Apr 13, 2010, 6:14:16 AM4/13/10
to asna...@googlegroups.com
Toma!!
eso es justo lo que quería, gracias Joseba!
pd: es descendants() por si alguien copia y pega :D

> --
> -----------------------------------------------------------------------
> ASNativos
> www.5dms.com
> subscripciones/desubscripciones
> http://asnativos.5dms.com
> -----------------------------------------------------------------------
>
> To unsubscribe, reply using "remove me" as the subject.

Reply all
Reply to author
Forward
0 new messages