Added support for basic xml operations

Tweaked and beautified some main code a bit.
Refactored some of the test debug support.