Función getName() de PHP
Definición y uso
La función getName() obtiene el nombre del elemento XML del objeto SimpleXMLElement.
Si tiene éxito, la función devuelve el nombre del elemento XML actual. Si falla, devuelve false.
Sintaxis
class SimpleXMLElement { string getName() }
Ejemplo
Archivo XML:
<?xml version="1.0" encoding="ISO-8859-1"?> <nota> <to>George</to> <from>John</from> <heading>Recordatorio</heading> <b:body>¡No olvide la reunión!</b:body> </nota>
Código PHP:
<?php if (file_exists('test.xml')) { $xml = simplexml_load_file('test.xml'); } echo $xml->getName(); foreach($xml->children() as $child) { echo $child->getName(); } ?>
La salida es similar a:
nota to from heading body