Checking before we write
Also for the emitted XML
Merge pull request #11 from paultag/bugfix/xml-fix

Bugfix/xml fix