If this is only happening with CSV imported files, then I suspect the issue is not a bug in the XML export code, but rather something in the CSV.
Are you using Excel to prepare your CSV? If so, and if this is only happening with files imported via CSV, then it's possible that the CSV contains non-UTF-8 characters. In some cases, it might be possible to create a CSV that's valid enough to import, but still contains characters that can cause problems later. This can also happen if you've prepared your data by cutting and pasting it into a spreadsheet from something like a Word document that is not saved with UTF-8 encoding.
In general, we recommend using LibreOffice
Calc for CSV preparation. Microsoft likes to use its own custom line ending characters and character encoding (such as Win-1252), by default, or else adopt the computer's default encoding, which is not always UTF-8. These can lead to CSV import issues if not properly addressed. Later versions of Excel now contain CSV UTF-8 save options, so the situation is much improved, but we still hear of issues due to this. Not only is Calc open source, but it also allows you to set the character encoding, separator character, and string delimiter every time you open a CSV, with a preview of the resulting formatting when represented in a spreadsheet, to ensure the data is displayed correctly. It also makes saving with the correct encoding and line endings much simpler.
Are you able to edit the record in AtoM's interface? If it is caused by unexpected characters, you may be able to identify and fix them in edit mode, since AtoM's display is UTF-8. Non-UTF-8 characters may be visible, allowing you to delete and re-type them.
Alternatively, are you able to export this problem record as a CSV file? It may be possible to open it with UTF-8 encoding and identify problem characters. Alternatively, opening it in a text editor instead would allow you to see the raw input, which may make finding and fixing any problem characters easier. However, if you do this, be very careful about editing it this way! If you accidentally delete a comma separator or a string delimiter, you could end up making the CSV malformed, so be sure to Save As and keep the original.
I will consult with our team and see if they have any other suggestions. Let us know how it goes in the meantime.
Cheers,