don't toString() at iteration end

Check XMP datum exists before converting to string, otherwise
toString() will segfault; fixing the fix in 8e80edcd5048858e.