How can you output data extracted from an XML file using SimpleXML in a structured format, such as a table?

To output data extracted from an XML file using SimpleXML in a structured format, such as a table, you can loop through the XML elements and display them within HTML table tags. This can be achieved by accessing the XML elements using SimpleXML functions and then echoing the data within table rows and cells.

<?php
$xml = simplexml_load_file('data.xml');

echo '<table>';
echo '<tr><th>Name</th><th>Age</th></tr>';

foreach ($xml->person as $person) {
    echo '<tr>';
    echo '<td>' . $person->name . '</td>';
    echo '<td>' . $person->age . '</td>';
    echo '</tr>';
}

echo '</table>';
?>