# XML, can't seem to access some elements

**URL:** <https://forum.kirupa.com/t/xml-cant-seem-to-access-some-elements/297814>\
**Category:** flash\
**Created:** [October 8, 2009, 5:29pm UTC](https://forum.kirupa.com/t/xml-cant-seem-to-access-some-elements/297814 "2009-10-08T17:29:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ann0yed](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@ann0yed](https://forum.kirupa.com/u/ann0yed)\
**Post date:** [October 8, 2009, 5:29pm UTC](https://forum.kirupa.com/t/xml-cant-seem-to-access-some-elements/297814/1 "2009-10-08T17:29:55Z")

</div>

Here’s an example of my XML:

\</State\>  
\<State name=“AR” eVts=“6” pCls=“8:30 PM EST”\>  
\<PrecRepPct\>11\</PrecRepPct\>  
\<Candidates\>  
\<Cand name=“McCain” party=“R” pct=“55” tab=“194,543” win=“Y” /\>  
\<Cand name=“Obama” party=“D” pct=“44” tab=“155,526” win=“N” /\>  
\</Candidates\>  
\</State\>

There are 50 of those, one for each US state.

I have to pass each item to an array (all, “names”, “eVts”, “pCls” and etc.) so that I can access them later. I’ve managed to get down to “Candidates” and this is where it all breaks down, I can’t seem to get at the stuff in “Cand”. This is what it looks like in my code:

function parseData():void {

for ( var i:uint = 0; i \< simpleXML.elements().length(); i++ ) {  
stateAbbreviation = simpleXML.State\*.@name;  
electoralVotes = simpleXML.State\*.@eVts;  
pollClosing = simpleXML.State\*.@pCls;

//that works fine, so then I try to go further - skipping “PrecRepPct” because I don’t need it

for ( var j:uint = 0; j \< simpleXML.State\*.Candidates.elements().length(); j++ ) {  
trace(j)  
//gets me 0101010101010101, which i’m assuming is “Cand” being in position [0] and [1]? Anyway, means I’m in there right?

//then I want to get all the “name”, “party”, etc. values from within “Cand” and push them into their arrays, but I can’t seem to get there. I tried this:

for ( var k:uint = 0; k \< simpleXML.State\*.Candidates[j].Cand.length(); k++ ) {  
trace(k);  
candidateName.push(simpleXML.State\*.Candidates[j].Cand[k].@name);

}  
}  
}  
}

//I get: TypeError: Error #1010: A term is undefined and has no properties.

I’m wondering if its because there are two "Cand"s, or "Cand.length(); isn’t the right thing to use or whatever, I’ve totally hit the wall. Anyone care to give me some input? It would be greatly appreciated!

-jonathan
