PHP getName() Function
Definition and Usage
The getName() function retrieves the name of the XML element from the SimpleXMLElement object.
If successful, the function returns the name of the current XML element. If failed, it returns false.
Syntax
class SimpleXMLElement { string getName() }
Example
XML File:
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <b:body>Don't forget the meeting!</b:body> </note>
PHP Code:
<?php if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); } echo $xml->getName(); foreach($xml->children() as $child) { echo $child->getName(); } ?>
Output similar to:
note to from heading body