1

I'm trying to loop every skill that can be found in EVE Online (API Skilltree) but the following code only loop through the first 7 skill groups.

$skilltree_url = file_get_contents('https://api.eveonline.com/eve/SkillTree.xml.aspx', 0, null, null);
$skilltree = simplexml_load_string($skilltree_url);

foreach($skilltree->result->rowset->row AS $skill) {
    var_dump($skill->rowset->row->attributes()->typeID);
}

What have I done wrong?

Thanks in advance.

EDIT

This code:

$xml = simplexml_load_file('https://api.eveonline.com/eve/SkillTree.xml.aspx');
$skilltree = $xml->result->rowset;
foreach($skilltree->row as $skill) {
    var_dump($skill->rowset->row->attributes()->typeID);
}

Prints this:

object(SimpleXMLElement)[7]
  string '2403' (length=4)
object(SimpleXMLElement)[6]
  string '3184' (length=4)
object(SimpleXMLElement)[7]
  string '3300' (length=4)
object(SimpleXMLElement)[6]
  string '3319' (length=4)
object(SimpleXMLElement)[7]
  string '3327' (length=4)
object(SimpleXMLElement)[6]
  string '3348' (length=4)
object(SimpleXMLElement)[7]
  string '3355' (length=4)
object(SimpleXMLElement)[6]
  string '3363' (length=4)
object(SimpleXMLElement)[7]
  string '3380' (length=4)
object(SimpleXMLElement)[6]
  string '3392' (length=4)
object(SimpleXMLElement)[7]
  string '3402' (length=4)
object(SimpleXMLElement)[6]
  string '3413' (length=4)
object(SimpleXMLElement)[7]
  string '3426' (length=4)
object(SimpleXMLElement)[6]
  string '3436' (length=4)
object(SimpleXMLElement)[7]
  string '3443' (length=4)
object(SimpleXMLElement)[6]
  string '3449' (length=4)
object(SimpleXMLElement)[7]
  string '3551' (length=4)
object(SimpleXMLElement)[6]
  string '3731' (length=4)
object(SimpleXMLElement)[7]
  string '3755' (length=4)
object(SimpleXMLElement)[6]
  string '3893' (length=4)
object(SimpleXMLElement)[7]
  string '4385' (length=4)
object(SimpleXMLElement)[6]
  string '4411' (length=4)
object(SimpleXMLElement)[7]
  string '9955' (length=4)
object(SimpleXMLElement)[6]
  string '11015' (length=5)
object(SimpleXMLElement)[7]
  string '11075' (length=5)
object(SimpleXMLElement)[6]
  string '11082' (length=5)
object(SimpleXMLElement)[7]
  string '11204' (length=5)
object(SimpleXMLElement)[6]
  string '11207' (length=5)
object(SimpleXMLElement)[7]
  string '11208' (length=5)
object(SimpleXMLElement)[6]
  string '11395' (length=5)
object(SimpleXMLElement)[7]
  string '11433' (length=5)
object(SimpleXMLElement)[6]
  string '11566' (length=5)
object(SimpleXMLElement)[7]
  string '11569' (length=5)
object(SimpleXMLElement)[6]
  string '11579' (length=5)
object(SimpleXMLElement)[7]
  string '11584' (length=5)
object(SimpleXMLElement)[6]
  string '11858' (length=5)
object(SimpleXMLElement)[7]
  string '12092' (length=5)
object(SimpleXMLElement)[6]
  string '12179' (length=5)
object(SimpleXMLElement)[7]
  string '12180' (length=5)
object(SimpleXMLElement)[6]
  string '12201' (length=5)
object(SimpleXMLElement)[7]
  string '12241' (length=5)
object(SimpleXMLElement)[6]
  string '12305' (length=5)
object(SimpleXMLElement)[7]
  string '12365' (length=5)
object(SimpleXMLElement)[6]
  string '12368' (length=5)
object(SimpleXMLElement)[7]
  string '12441' (length=5)
object(SimpleXMLElement)[6]
  string '12484' (length=5)
object(SimpleXMLElement)[7]
  string '12834' (length=5)
object(SimpleXMLElement)[6]
  string '13278' (length=5)
object(SimpleXMLElement)[7]
  string '13279' (length=5)
object(SimpleXMLElement)[6]
  string '16069' (length=5)
object(SimpleXMLElement)[7]
  string '16281' (length=5)
object(SimpleXMLElement)[6]
  string '16591' (length=5)
object(SimpleXMLElement)[7]
  string '16594' (length=5)
object(SimpleXMLElement)[6]
  string '17940' (length=5)
object(SimpleXMLElement)[7]
  string '18025' (length=5)
object(SimpleXMLElement)[6]
  string '18580' (length=5)
object(SimpleXMLElement)[7]
  string '19430' (length=5)
object(SimpleXMLElement)[6]
  string '19759' (length=5)
object(SimpleXMLElement)[7]
  string '20127' (length=5)
object(SimpleXMLElement)[6]
  string '20209' (length=5)
object(SimpleXMLElement)[7]
  string '20327' (length=5)
object(SimpleXMLElement)[6]
  string '20342' (length=5)
object(SimpleXMLElement)[7]
  string '20433' (length=5)
object(SimpleXMLElement)[6]
  string '20494' (length=5)
object(SimpleXMLElement)[7]
  string '20524' (length=5)
object(SimpleXMLElement)[6]
  string '21059' (length=5)
object(SimpleXMLElement)[7]
  string '21071' (length=5)
object(SimpleXMLElement)[6]
  string '21603' (length=5)
object(SimpleXMLElement)[7]
  string '21610' (length=5)
object(SimpleXMLElement)[6]
  string '21666' (length=5)
object(SimpleXMLElement)[7]
  string '21668' (length=5)
object(SimpleXMLElement)[6]
  string '21718' (length=5)
object(SimpleXMLElement)[7]
  string '21802' (length=5)
object(SimpleXMLElement)[6]
  string '21803' (length=5)
object(SimpleXMLElement)[7]
  string '22043' (length=5)
object(SimpleXMLElement)[6]
  string '22172' (length=5)
object(SimpleXMLElement)[7]
  string '22242' (length=5)
object(SimpleXMLElement)[6]
  string '22536' (length=5)
object(SimpleXMLElement)[7]
  string '22541' (length=5)
object(SimpleXMLElement)[6]
  string '22551' (length=5)
object(SimpleXMLElement)[7]
  string '22552' (length=5)
object(SimpleXMLElement)[6]
  string '22578' (length=5)
object(SimpleXMLElement)[7]
  string '22761' (length=5)
object(SimpleXMLElement)[6]
  string '22806' (length=5)
object(SimpleXMLElement)[7]
  string '23069' (length=5)
object(SimpleXMLElement)[6]
  string '23087' (length=5)
object(SimpleXMLElement)[7]
  string '23566' (length=5)
object(SimpleXMLElement)[6]
  string '23950' (length=5)
object(SimpleXMLElement)[7]
  string '24241' (length=5)
object(SimpleXMLElement)[6]
  string '24242' (length=5)
object(SimpleXMLElement)[7]
  string '24268' (length=5)
object(SimpleXMLElement)[6]
  string '24270' (length=5)
object(SimpleXMLElement)[7]
  string '24311' (length=5)
object(SimpleXMLElement)[6]
  string '24562' (length=5)
object(SimpleXMLElement)[7]
  string '24568' (length=5)
object(SimpleXMLElement)[6]
  string '24571' (length=5)
object(SimpleXMLElement)[7]
  string '24606' (length=5)
object(SimpleXMLElement)[6]
  string '24613' (length=5)
object(SimpleXMLElement)[7]
  string '24624' (length=5)
object(SimpleXMLElement)[6]
  string '24625' (length=5)
object(SimpleXMLElement)[7]
  string '24764' (length=5)
object(SimpleXMLElement)[6]
  string '25233' (length=5)
object(SimpleXMLElement)[7]
  string '25530' (length=5)
object(SimpleXMLElement)[6]
  string '25544' (length=5)
object(SimpleXMLElement)[7]
  string '25718' (length=5)
object(SimpleXMLElement)[6]
  string '25739' (length=5)
object(SimpleXMLElement)[7]
  string '25863' (length=5)
object(SimpleXMLElement)[6]
  string '26224' (length=5)
object(SimpleXMLElement)[7]
  string '26252' (length=5)
object(SimpleXMLElement)[6]
  string '27911' (length=5)
object(SimpleXMLElement)[7]
  string '27936' (length=5)
object(SimpleXMLElement)[6]
  string '28073' (length=5)
object(SimpleXMLElement)[7]
  string '28164' (length=5)
object(SimpleXMLElement)[6]
  string '28261' (length=5)
object(SimpleXMLElement)[7]
  string '28373' (length=5)
object(SimpleXMLElement)[6]
  string '28374' (length=5)
object(SimpleXMLElement)[7]
  string '28585' (length=5)
object(SimpleXMLElement)[6]
  string '28604' (length=5)
object(SimpleXMLElement)[7]
  string '28609' (length=5)
object(SimpleXMLElement)[6]
  string '28631' (length=5)
object(SimpleXMLElement)[7]
  string '28656' (length=5)
object(SimpleXMLElement)[6]
  string '28879' (length=5)
object(SimpleXMLElement)[7]
  string '29029' (length=5)
object(SimpleXMLElement)[6]
  string '30324' (length=5)
object(SimpleXMLElement)[7]
  string '30532' (length=5)
object(SimpleXMLElement)[6]
  string '30650' (length=5)
object(SimpleXMLElement)[7]
  string '30788' (length=5)
object(SimpleXMLElement)[6]
  string '32339' (length=5)
object(SimpleXMLElement)[7]
  string '32435' (length=5)
object(SimpleXMLElement)[6]
  string '32797' (length=5)
object(SimpleXMLElement)[7]
  string '32856' (length=5)
object(SimpleXMLElement)[6]
  string '32918' (length=5)
object(SimpleXMLElement)[7]
  string '32999' (length=5)
hakre
  • 193,403
  • 52
  • 435
  • 836
Airikr
  • 6,258
  • 15
  • 59
  • 110
  • If you var_dump the whole array (on parent index) first, what do you get? – art2 Dec 12 '12 at 13:31
  • Seems to work fine here, getting all the top groups and the their first typeID. Got anymore things you're using to run this? – CE_REAL Dec 12 '12 at 13:36
  • Try running this `result->rowset->row AS $skill) {     var_dump($skill->attributes()->groupName); }` this results in all the group name for me. – CE_REAL Dec 12 '12 at 13:37
  • I'm getting this if I move out the `var_dump()` from the foreach loop: `object(SimpleXMLElement)[9] string '2403' (length=4)` – Airikr Dec 12 '12 at 13:38
  • CE_REAL: I want to get all of the skill groups. Not the first 7 groups which I'm getting with that code. I want to reach out for the `TypeID` for every skill that are in these skill groups – Airikr Dec 12 '12 at 13:42
  • @ErikEdgren what PHP version are you using, it seems to me that your loop isn't working correctly, because you're only getting the first typeID, when I put the var_dump outside of the loop (after the loop is finished) I get the last typeID that's found in the xml. – CE_REAL Dec 12 '12 at 13:44
  • Hm. Weird. If I do so too, I'm only getting the first 7 skill groups as I said :P :S I have PHP v5.3.8 according to `phpinfo()` – Airikr Dec 12 '12 at 13:47
  • But with your code that you gave me, I'm getting all of the skill groups – Airikr Dec 12 '12 at 13:53

1 Answers1

1

This should work, and is a bit easier to use:

$xml = simplexml_load_file('https://api.eveonline.com/eve/SkillTree.xml.aspx');
$skilltree = $xml->result->rowset;
foreach($skilltree->row as $skill) {
    var_dump($skill->rowset->row->attributes()->typeID);
}

Edit:

This should be the whole thing you need, rest of the attributes you should be able to figure out by yourself:

$xml = simplexml_load_file('https://api.eveonline.com/eve/SkillTree.xml.aspx');
$skilltree = $xml->result->rowset;
foreach($skilltree->row as $skillgroup) {
    echo 'Group name: ' .$skillgroup->attributes()->groupName .'<br />';
    foreach ($skillgroup->rowset->row as $skill) {
        echo 'Type ID: ' .$skill->attributes()->typeID .'<br />';
        echo 'Type name: ' .$skill->attributes()->typeName .'<br />';
    }
    echo '<br />';
}
CE_REAL
  • 384
  • 5
  • 13
  • Thanks :) But it doesn't prints every skill that are in the skill groups. Please see my edit in my question. But I'm questing that you have chosen to only print out the skill groups ID. – Airikr Dec 12 '12 at 14:00
  • @ErikEdgren check my update, should be what you need. Mark the answer as accepted if this is what you need. – CE_REAL Dec 12 '12 at 15:37
  • Sweet! :D So I had to have 2 `foreach` loops to accomplish this. Many thanks :D – Airikr Dec 12 '12 at 16:07
  • Yes, because of the many skill groups, which each have a couple of skills, makes many + many which results in a foreach for both, at least that's that's as far as I know the easiest. Glad that I could have helped. – CE_REAL Dec 12 '12 at 19:47
  • Very true :) Their XML page isn't that small. Many thanks once again :) – Airikr Dec 13 '12 at 08:28