SimpleXMLElement
PHP Manual

SimpleXMLElement::getName

(PHP 5 >= 5.1.3, PHP 7)

SimpleXMLElement::getNameGets the name of the XML element

说明

public string SimpleXMLElement::getName ( void )

Gets the name of the XML element.

返回值

The getName method returns as a string the name of the XML tag referenced by the SimpleXMLElement object.

范例

Note:

Listed examples may include example.php, which refers to the XML string found in the first example of the basic usage guide.

Example #1 Get XML element names

<?php
include 'example.php';
$sxe = new SimpleXMLElement($xmlstr);

echo 
$sxe->getName() . "\n";

foreach (
$sxe->children() as $child)
{
    echo 
$child->getName() . "\n";
}

?>

以上例程会输出:

movies
movie


SimpleXMLElement
PHP Manual