Are there any best practices for reading and outputting XML data using simplexml in PHP?

When reading and outputting XML data using simplexml in PHP, it is important to use proper error handling to catch any issues that may arise during parsing. Additionally, it is recommended to use the `asXML()` method to output the XML data in a formatted and structured way for easier readability.

<?php

// Load the XML file
$xml = simplexml_load_file('data.xml');

// Check if the XML file was loaded successfully
if ($xml) {
    // Output the XML data in a formatted way
    echo $xml->asXML();
} else {
    // Handle any errors that occur during parsing
    echo "Error loading XML file";
}

?>