Added support for basic xml operations

Tweaked and beautified some main code a bit.
Refactored some of the test debug support.
Fixed subtle flatten XML bug when empty nodes
Added some tests for asXML call
Added docs for asXML function
Some annoying missing empty lines