Funzione getName() PHP

Definizione e uso

La funzione getName() ottiene il nome dell'elemento XML dall'oggetto SimpleXMLElement.

Se ha successo, la funzione restituisce il nome dell'elemento XML corrente. Se fallisce, restituisce false.

Sintassi

class SimpleXMLElement
{
string getName()
}

Esempio

File XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Ricordatorio</heading>
<b:body>Non dimenticare l'incontro!</b:body>
</note>

Codice PHP:

<?php
if (file_exists('test.xml'))
  {
  $xml = simplexml_load_file('test.xml');
  }
echo $xml->getName();
foreach($xml->children() as $child)
  {
  echo $child->getName();
  }
?>

Output simile a:

note
to
from
heading
body