refactoring xml generation