It seems like you have answered your own question almost.
1. Servlet gets invoked with request
2. Build relevant XML
3. Get response output stream
4. Write content type
5. Dump XML
6.
Profit!
Do you have a more specific question?
I'd recommend reading this
servlet tutorial.
This code might be a very simple example of what you want. It doen't do any error checking and I make no guarantees to it's correctness!