Attributs de balise XML en PHP

Supposons maintenant que la balise ait des attributs :

test.xml<root>
  <tag attr="val">text</tag>
</root>

Pour obtenir la valeur de l'attribut, il faut accéder à $xml->tag comme à un tableau :

index.php<?php
  echo $xml->tag['attr']; // affichera 'val'
?>

Cependant, si on affiche simplement $xml->tag, on obtiendra le texte de la balise :

index.php<?php
  echo $xml->tag; // affichera 'text'
?>
Задание 1

Voici le XML suivant :

html<root>
  <user age="23" salary="1000">john</user>
</root>

Affichez le nom, l'âge et le salaire de l'utilisateur.