For downloading, instead of opening in window, You are doing exactly the same thing, but on top of that You need to set headers before echoing the XML contents.
Check this question and it's accepted answer to see what shall be done before echoing...