What are the best practices for delivering XML content in PHP?

When delivering XML content in PHP, it is important to properly set the content type header to ensure the XML is displayed correctly in the browser. This can be done using the header() function in PHP. Additionally, it is recommended to use functions like simplexml_load_string() or simplexml_load_file() to parse and manipulate XML data effectively.

// Set the content type header for XML
header('Content-type: text/xml');

// Sample XML content
$xmlString = '<root><name>John Doe</name><age>30</age></root>';

// Parse the XML string
$xml = simplexml_load_string($xmlString);

// Output the XML
echo $xml->asXML();