在PHP SimpleXML中获取节点名称

I've alread saw this question and answer but I wasn't able to use it.

This is my code:

//Get grandparents of MyRefNode
$GrandParents = $MyXml->xpath('//MyRefNode/../..');
//Loop grandparents 
foreach ($GrandParents as $GrandParent){
    //Count each GrandParent's children
    $count = $GrandParent->count(); 
    echo '<br/> Children count = '.$count;
    //Get GrandParent's Tag name **NOT WORKING**
    $TName = $GrandParent->xpath('./name()')
    echo '<br/> Tag Name = '.$TName;
}

You should be able to use SimpleXMLElement::getName() instead :

foreach ($GrandParents as $GrandParent){
    ....
    $TName = $GrandParent->getName();
    echo '<br/> Tag Name = '.$TName;
}