Dated but relevant, because searching for the solution is what brought me to this post.
The XML files are posted on the retropie wiki itself. So perhaps don't worry about generating your own.
https://github.com/RetroPie/RetroPie-Setup/wiki/MAME#mame4all-piIn my case I was using "arcade" which maps to retroarch using mame2003 library.
Anyway after a lot of time wasted and headache, all I had to do was download the proper XML/dat file from the wiki, copy it to my pi, then follow the steps progets pointed out.
This worked for many ROMs which made me quite happy. But it didn't work for all roms. I still dont really understand Mame versioning. I'm guessing that I have more ROMs than what was included in mame2003? No idea.