0

I'm tring to get all content from this xml: https://api.eveonline.com/eve/SkillTree.xml.aspx

To save it on a MySQL DB.

But there are some data missing...

Could any1 that understand PHP, Array() and XML help me, please?

This is my code to get the content:

<?php

    $filename = 'https://api.eveonline.com/eve/SkillTree.xml.aspx';
    $xmlbalance = simplexml_load_file($filename);
    $skills = array();

    for ($x=0;$x<sizeOf($xmlbalance->result->rowset->row);$x++) {
         $groupName = $xmlbalance->result->rowset->row[$x]->attributes()->groupName;
         $groupID = $xmlbalance->result->rowset->row[$x]->attributes()->groupID;
         for ($y=0;$y<sizeOf($xmlbalance->result->rowset->row[$x]->rowset->row);$y++) {
             $skills[$x]["skillID"] = "".$xmlbalance->result->rowset->row[$x]->rowset->row[$y]->attributes()->typeID;
             $skills[$x]["skillName"] = "".$xmlbalance->result->rowset->row[$x]->rowset->row[$y]->attributes()->typeName;            
             $skills[$x]["skillDesc"] = "".$xmlbalance->result->rowset->row[$x]->rowset->row[$y]->description;
             $skills[$x]["skillRank"] = "".$xmlbalance->result->rowset->row[$x]->rowset->row[$y]->rank;
             $skills[$x]["skillPrimaryAtr"] = "".$xmlbalance->result->rowset->row[$x]->rowset->row[$y]->requiredAttributes->primaryAttribute;
             $skills[$x]["skillSecondAtr"] = "".$xmlbalance->result->rowset->row[$x]->rowset->row[$y]->requiredAttributes->secondaryAttribute;

             $o = 0;
             for ($z=0;$z<sizeOf($xmlbalance->result->rowset->row[$x]->rowset->row[$y]->rowset->row);$z++) {
                 if ($xmlbalance->result->rowset->row[$x]->rowset->row[$y]->rowset->attributes()->name == "requiredSkills") {
                     $skills[$x]["requiredSkills"]["".$xmlbalance->result->rowset->row[$x]->rowset->row[$y]->rowset->row[$z]->attributes()->typeID] = "".$xmlbalance->result->rowset->row[$x]->rowset->row[$y]->rowset->row[$z]->attributes()->skillLevel;
                     $o++;
                 }
             }

         }

    }
     echo '<pre>'; print_r($skills); echo '</pre>';

?>

If you go to the original XML (link), at line 452, you will see:

  <row groupName="Spaceship Command" groupID="257">

And that isn't show in my array (link)...

That is one thing that i found that is missing... I think that probally have more content that is missing too..

Why? How to fix it, please?

Thank you!!!

1 Answer 1

1

You will only get a total of sizeof($xmlbalance->result->rowset->row) records. Because, in your 2nd for loop, you are basically storing your result in the same array element that is $skills[$x].

Try this (I also higly encourage you to be as lazy as you can when you write code - by lazy I mean, avoid repeating / rewriting the same code over and over if possible) :

$filename = 'https://api.eveonline.com/eve/SkillTree.xml.aspx';
$xmlbalance = simplexml_load_file($filename);
$skills = array();    
foreach ($xmlbalance->result->rowset->row as $row)
{
    $groupName = $row->attributes()->groupName;
    $groupID = $row->attributes()->groupID;

    foreach ($row->rowset->row as $subRow) 
    {
        $skill['skillID'] = (string) $subRow->attributes()->typeID;
        $skill['skillName'] = (string) $subRow->attributes()->typeName;
        $skill['skillDesc'] = (string) $subRow->description;
        $skill['skillRank'] = (string) $subRow->rank;
        $skill['skillPrimaryAtr'] = (string) $subRow->requiredAttributes->primaryAttribute;
        $skill['skillSecondAtr'] = (string) $subRow->requiredAttributes->secondaryAttribute;

        foreach ($subRow->rowset as $subSubRowset) 
        {
            if ($subSubRowset->attributes()->name == 'requiredSkills') 
            {
                foreach ($subSubRowset->row as $requiredSkill) 
                {
                    $skill['requiredSkills'][(string) $requiredSkill->attributes()->typeID] = (string) $requiredSkill['skillLevel'];
                }
            }
        }

        $skills[] = $skill;
    }
}
print_r($skills);
Sign up to request clarification or add additional context in comments.

3 Comments

The xml that i need to get is much complicated than those simple xml in question that u suggested. The code is working, but that is missing some content... I need help to find why some content is missing.
Thank you for ur help ;) I tried, but the code isn't working too =( With this new code, i can't get the skill's Desc, skill's Rank and the required's skills list. Look: pastebin.com/CD2nSrG5 ... Ahhh this xml is so complicated and in my opnion very bad written :P
Ty very much!!! Its all woorking!! very nice! Thanks for simplifying the code with the vars ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.