Search code examples
phpxmlxml-parsingsteam

Can't parse node from Steam XML


I'm trying to parse the steamID64 from http://steamcommunity.com/id/crafz?xml=1

$sxml = simplexml_load_file('http://steamcommunity.com/id/crafz?xml=1') or die("died"); 
$result = $sxml->profile[0]->steamID64[0];
settype($result, "string");
echo $result;

Error: Notice: Trying to get property of non-object in D:\xampp\htdocs\tfpickup\php\first.php on line 8

I tried different variants for hours but can't figure out why it's not working. Thanks for any answers in advance.


Solution

  • The root node (<profile>) of the Steam profile XML is ignored. So it's actually a bit easier than you're thinking:

    $sxml = simplexml_load_file(...);
    $result = (string) $sxml->steamID64;