You have to use proper content-type, as the others have said.
I recommend you to use XMLReader.
Or if you want a n easier way, then try to use Heredoc string syntax with sprintf and htmlspecialchars to encode values with characters that have special meanings in XML (like <>&)