Skip to main content
June 13, 2009
Answered

xml parsing with diferent node names

  • June 13, 2009
  • 1 reply
  • 520 views

Hello,

How can I know the label of diferent node names parsing xml?

I'm using something like

this is the xml structure

<bd>

<tabela label="design"/>

<familia label="familias"/>

<tabela label="produtos"/>

</bd>

this is the as code

var myXML:XML = new XML();
myXML = XML(event.target.data);
for(var i=0; i<=myXML.length(); i++) {
     trace("Nome da tabela " + myXML.tabela.label + "\n");
}

this traces my node names, but it skips the midle one, because he is not named as tabela

what I need is to know how many and what names my xml has

Thanks

This topic has been closed for replies.
Correct answer

label is an attribute...

for(var i:uint = 0; i < l; i++){
    trace(xm.children().@label);
}

1 reply

June 13, 2009

When you don't know the structure, you can use the children() method. Here's a little sample using inline XML:

var xm:XML =
<bd>
    <tabela label="design"/>
    <familia label="familias"/>
    <tabela label="produtos"/>
</bd>;

var l = xm.children().length();
for(var i:uint = 0; i < l; i++){
    trace(xm.children().toXMLString());
}

June 13, 2009

Hello,

thanks for reply

yep, that traces the complete structure of loaded xml, but how do I get just the node labels?

with this I get un error

var myXML:XML = new XML();
myXML = XML(event.target.data);
for(var i=0; i<=myXML.children().length(); i++) {
     trace("Nome da tabela " + myXML.children().label + "\n");
}

Error #1010: A term is undefined and has no properties.

    /*
    var l = myXML.children().length();
    for(var i:uint = 0; i < l; i++){
        trace(myXML.children().toXMLString());
    }
    */

Correct answer
June 13, 2009

label is an attribute...

for(var i:uint = 0; i < l; i++){
    trace(xm.children().@label);
}