The code below should loop through the nodes which is what it sounds like you're trying to do. The code you have is looping through the tags and the tags under each of those which do not contain any IDs.
$doc = new DOMDocument;
$doc->loadXML($result);
$nodes = $doc->getElementsByTagName('node');
foreach ($nodes as $node) {
$id = intval($node->getAttribute('id'));
$lat = intval($node->getAttribute('lat'));
$lon = intval($node->getAttribute('lon'));
var_dump($node);
}
Hope this helps at least get you on the right track.