2013-02-02 71 views
-2

下面是XML文件: http://steamcommunity.com/profiles/76561198044834372/games?tab=all&xml=1读取数据流的XML文件

我试图用SimpleXML做到这一点,但没有成功。

有人可以给我的代码来阅读游戏标题吗?

例如,

<games> 
<game> 
<appID>570</appID> 
<name> 
<![CDATA[ Dota 2 ]]> 
</name> 
<logo> 
<![CDATA[ 
http://media.steampowered.com/steamcommunity/public/images/apps/570/d4f836839254be08d8e9dd333ecc9a01782c26d2.jpg 
]]> 
</logo> 
<storeLink> 
<![CDATA[ http://steamcommunity.com/app/570 ]]> 
</storeLink> 
<hoursLast2Weeks>3.6</hoursLast2Weeks> 
<hoursOnRecord>3.6</hoursOnRecord> 
</game> 

我希望游戏名称: 游戏 - >游戏 - >名字在名单上每场比赛的 。

在此先感谢。

+1

“有人能给我代码来阅读游戏标题吗?”,我们没有代码,但口香糖。你要? –

+0

我很乐意获得使用XML读取函数的解释。 – user1701227

+0

[简单程序到xml文件的CRUD节点和节点值]的可能重复(http://stackoverflow.com/questions/4906073/a-simple-program-to-crud-node-and-node-values-of -xml文件) – Gordon

回答

2

无论如何,我认为您首先需要看到“如何提出问题”。

$xml = file_get_contents("http://steamcommunity.com/profiles/76561198044834372/games?tab=all&xml=1"); 
$xml = simplexml_load_string($xml); 
foreach ($xml->games->game as $game) { 
    echo (string) $game->name; 
} 

输出;

 
Dota 2 
Grand Theft Auto IV 
Champions Online: Free For All 
Company of Heroes 
Company of Heroes: Opposing Fronts 
Company of Heroes: Tales of Valor 
CrimeCraft GangWars 
Darksiders 
DC Universe Online 
Deus Ex: Human Revolution 
Global Agenda 
HOMEFRONT Demo 
Metro 2033 
Red Faction: Armageddon 
Sniper: Ghost Warrior 
Team Fortress 2 
The Lord of the Rings Online™ 
Tribes: Ascend