rewritten tofile using xml library