Prepare new XML earlier

If there's an error merging, this allows us to report it earlier and avoid
having to roll anything back.