What potential issues may arise when outputting XML data directly in PHP for file downloads?

One potential issue that may arise when outputting XML data directly in PHP for file downloads is that special characters in the XML may not be properly encoded, leading to invalid XML. To solve this issue, you can use the `htmlspecialchars()` function to encode special characters before outputting the XML data.

// Sample XML data
$xmlData = "<data><name>John Doe</name><age>30</age></data>";

// Encode special characters in XML data
$xmlDataEncoded = htmlspecialchars($xmlData);

// Output XML data for download
header('Content-Type: text/xml');
header('Content-Disposition: attachment; filename="data.xml"');
echo $xmlDataEncoded;