Enhance XML reader/writer

Also catch some edge cases
WIP
WIP
WIP
Enhance XML reader/writer

Also catch some edge cases
WIP
WIP