You can use the DOM functions to generate an XML document in memory (which is what a DOM is), then output it.
Be aware that the DOM functions do not check for things which are invalid when you're creating a document, so you can create badly formed documents - for example, using attributes with illegal names.
Pay special attention to getting the character encoding right with DOM. All functions expect UTF8 regardless of what encoding your app is using.
Mark