此(var_dump)是网站Alexa排名的XMLElement对象。我想要的只是读取RANK值(这里是4)。怎么弄? 我正在尝试:
打印(字符串)$ 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 :(得分: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()
来查看它是否是你正在寻找的那个。
希望这有帮助。