2012-02-27 9 views
1

これは(var_dump)WebサイトのAlexaランクのXMLElementオブジェクトです。私が望むのは、RANK値(ここでは4)を読み込むことだけです。それを得る方法? 私は次のようにしています:SimpleXMLElementオブジェクトの値を取得する方法は?

print(文字列)$ xml-> SD-> REACH-> RANK; //しかし

object(SimpleXMLElement)#1 (4) { 
    ["@attributes"]=> 
    array(4) { 
    ["VER"]=> 
    string(3) "0.9" 
    ["URL"]=> 
    string(10) "yahoo.com/" 
    ["HOME"]=> 
    string(1) "0" 
    ["AID"]=> 
    string(1) "=" 
    } 
    ["KEYWORDS"]=> 
    object(SimpleXMLElement)#2 (1) { 
    ["KEYWORD"]=> 
    array(2) { 
     [0]=> 
     object(SimpleXMLElement)#12 (1) { 
     ["@attributes"]=> 
     array(1) { 
      ["VAL"]=> 
      string(10) "On the Web" 
     } 
     } 
     [1]=> 
     object(SimpleXMLElement)#4 (1) { 
     ["@attributes"]=> 
     array(1) { 
      ["VAL"]=> 
      string(11) "Web Portals" 
     } 
     } 
    } 
    } 
    ["DMOZ"]=> 
    object(SimpleXMLElement)#14 (1) { 
    ["SITE"]=> 
    object(SimpleXMLElement)#7 (2) { 
     ["@attributes"]=> 
     array(3) { 
     ["BASE"]=> 
     string(10) "yahoo.com/" 
     ["TITLE"]=> 
     string(6) "Yahoo!" 
     ["DESC"]=> 
     string(133) "A major internet portal and service provider offering search results, customizable content, chatrooms, free e-mail, clubs, and pager." 
     } 
     ["CATS"]=> 
     object(SimpleXMLElement)#8 (1) { 
     ["CAT"]=> 
     array(3) { 
      [0]=> 
      object(SimpleXMLElement)#11 (1) { 
      ["@attributes"]=> 
      array(3) { 
       ["ID"]=> 
       string(45) "Top/Computers/Internet/On_the_Web/Web_Portals" 
       ["TITLE"]=> 
       string(22) "On the Web/Web Portals" 
       ["CID"]=> 
       string(6) "375197" 
      } 
      } 
      [1]=> 
      object(SimpleXMLElement)#10 (1) { 
      ["@attributes"]=> 
      array(3) { 
       ["ID"]=> 
       string(34) "Top/Computers/Companies/Yahoo_Inc." 
       ["TITLE"]=> 
       string(20) "Companies/Yahoo Inc." 
       ["CID"]=> 
       string(6) "376283" 
      } 
      } 
      [2]=> 
      object(SimpleXMLElement)#9 (1) { 
      ["@attributes"]=> 
      array(3) { 
       ["ID"]=> 
       string(118) "Top/Regional/North_America/United_States/California/Localities/S/Sunnyvale/Business_and_Economy/Computers_and_Internet" 
       ["TITLE"]=> 
       string(43) "Business and Economy/Computers and Internet" 
       ["CID"]=> 
       string(6) "627776" 
      } 
      } 
     } 
     } 
    } 
    } 
    ["SD"]=> 
    object(SimpleXMLElement)#13 (3) { 
    ["POPULARITY"]=> 
    object(SimpleXMLElement)#3 (1) { 
     ["@attributes"]=> 
     array(2) { 
     ["URL"]=> 
     string(10) "yahoo.com/" 
     ["TEXT"]=> 
     string(1) "4" 
     } 
    } 
    ["REACH"]=> 
    object(SimpleXMLElement)#6 (1) { 
     ["@attributes"]=> 
     array(1) { 
     ["RANK"]=> 
     string(1) "4" 
     } 
    } 
    ["RANK"]=> 
    object(SimpleXMLElement)#5 (1) { 
     ["@attributes"]=> 
     array(1) { 
     ["DELTA"]=> 
     string(2) "+0" 
     } 
    } 
    } 
} 
+0

DOMノードの属性です。子孫と属性ノードにアクセスする方法については、[ドキュメンテーション](http://www.php.net/manual/en/book.simplexml.php)をご覧ください。 –

+0

@Felix Kling私はこれを次のようにすることができます:$ xml-> SD-> REACH ["RANK"] – user774250

答えて

1

を働いていない私は、ドキュメントでこれを見つけた:

$XML = 
'<data> 
    <USERS> 
     <ID>alang</ID> 
     <NAME>Alan Gruskoff</NAME> 
     <ROLE>mgr</ROLE> 
    </USERS> 
</data>'; 

$xmlObject = new SimpleXMLElement($XML); 

$node = $xmlObject->children(); 

echo $node[0]->ID; 
echo $node[0]->NAME; 
echo $node[0]->ROLE; 

======

私はあなたがのchildren()をループする必要があります想像あなたが探しているものかどうかを確認するには、$node->getName()をクリックしてください。

これが役に立ちます。

関連する問題