Make sure the generated XML are valid according to NRML

This fixed both https://bugs.launchpad.net/oq-engine/+bug/1167324 and https://bugs.launchpad.net/oq-engine/+bug/1169106