Atributos de etiqueta XML en PHP
Supongamos que ahora la etiqueta tiene atributos:
test.xml<root>
<tag attr="val">texto</tag>
</root>
Para obtener el valor del atributo
necesitamos acceder a $xml->tag
como si fuera un array:
index.php<?php
echo $xml->tag['attr']; // mostrará 'val'
?>
Mientras que si simplemente mostramos $xml->tag,
obtendremos el texto de la etiqueta:
index.php<?php
echo $xml->tag; // mostrará 'texto'
?>
Задание 1
Dado el siguiente XML:
html<root>
<user age="23" salary="1000">john</user>
</root>
Muestre en pantalla el nombre, la edad y el salario del usuario.