Print XML Node e Attribute in PHP

2018-05-06

La seguente procedura, stampa il primo livello dei nodi di un oggetto XML in PHP.

echo "Node " . $xml->getName() . "<br />";
foreach($xml->attributes() as $attr_name => $attr_value) 
{
   echo "Attribute " . $attr_name.'="'.$attr_value.'"<br>';
}

foreach($xml->children() as $child)
{
  echo "Node " . $child->getName() . ": " . $child . "<br />";
  foreach($child->attributes() as $attr_name => $attr_value) 
  {
		echo "Attribute " . $attr_name.'="'.$attr_value.'"<br>';
  }
}