Feed XML file for user from link

I got XML data in variable made with DOMdocument from SQL data. I know I can save the XML file with DOMDocument-save() into a file. But say I had a link and when user clicks this link, i want to create the XML then, not before hand. And offer this XML file to user when he clicked the link. And XML data will be built based on the ID carried in the link. I am a bit confused.

Just output the XML with header(‘Content-type: text/xml’);

Yeah just figured that out, problem solved. Was thinking a simple problem too complicated.