Creating XML Documents with DOM
DOM is a read-write API. DOM documents are created not only by parsing text files, but also by creating new documents in memory out of nothing at all. These documents can then be serialized onto a stream or into a file.
http://cafeconleche.org/books/xmljava/chapters/ch10.html