attributes()` method of the SimpleXMLElement class along with a foreach loop. Here's an example :$xmlString = '<root><person name="John" age="30"/><person name="Jane" age="25"/></root>';
$xml = simplexml_load_string($xmlString);
foreach ($xml->person as $person) {
$name = $person['name'];
$age = $person['age'];
echo "Name: $name, Age: $age<br>";
}Name: John, Age: 30
Name: Jane, Age: 25simplexml_load_string()` function, which returns a SimpleXMLElement object. Then, we loop through each `person` element using a foreach loop. attributes()` method to get an array of attributes of the current element. name` and `age` attributes using array indexing, and print their values using the `echo` statement.