refactored common xml building method