I suggest you first master the database to xml step OUTSIDE the servlet environment. Once you can write your xml to a Writer or a String, then you can think about doing it in a servlet. A google search for "java xml tutorial" should lead you to a basic tutorial.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com