Cleanup: Refactoring XML output code to facilitate introduction of protocol xml output.