Moving xml generation to DOM