SimpleXMLElement获取对象的键

i am parsing the folloing xml

object(SimpleXMLElement)#23 (5) {
  ["version"]=>
  string(1) "2"
  ["data"]=>
  object(SimpleXMLElement)#21 (4) {
    ["record"]=>
    array(28) {
      [0]=>
      object(SimpleXMLElement)#20 (6) {
        ["name"]=>
        string(1) "1"
        ["line"]=>
        string(1) "1"

      }
      [1]=>
      object(SimpleXMLElement)#19 (6) {
        ["name"]=>
        string(1) "2"
        ["line"]=>
        string(1) "2"
      }

      .....

The code is very simple and its working fine

if(is_object($xml->data->record) && sizeof($xml->data->record)>0)
{
    $counter=0;
    foreach($xml->data->record as $key => $record)
    {
        $name = (string)$record->name;
        $line = (string)$record->line;      
    }
}      

The problem is that i can not find a way to get the array key 0,1 which i need them.

The $key on foreach return record

["record"]=>
    array(28) {
      [0]=>
      object(SimpleXMLElement)#20 (6) {
      }
      [1]=>
      object(SimpleXMLElement)#19 (6) {
      }

Any help appreciated