循环每一项技能而不仅仅是其中的一小部分

时间:2012-12-12 13:28:55

标签: php foreach simplexml api-eveonline

我正在尝试循环在EVE Online中可以找到的所有技能(API Skilltree),但以下代码仅循环通过前7个技能组。

$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);
}

我做错了什么?

提前致谢。

修改

此代码:

$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);
}

打印出来:

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)

1 个答案:

答案 0 :(得分:1)

这应该可行,并且使用起来更容易:

$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);
}

编辑:

这应该是您需要的全部内容,您应该能够自己弄清楚的其他属性:

$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 />';
}