PHP getName() Function
Description
The getName() function returns the name of the XML element.
Syntax
PHP getName() Function has the following syntax.
getName();
Return
Returns the name of the XML tag referenced by the SimpleXMLElement object, as a string
Example
Return the name of the XML element and the children:
<?php//www. ja v a 2s . c o m
$xml=<<<XML
<?xml version="1.0" standalone="yes"?>
<books>
<book id="1">Java</book>
<book id="2">PHP</book>
<book id="3">CSS</book>
</books>
XML;
$sxe=new SimpleXMLElement($xml);
echo $sxe->getName() . "\n";
foreach ($sxe->children() as $child){
echo $child->getName() . "\n";
}
?>
The code above generates the following result.