Generate proper XML IDs

The current code relies on the name of the file to generate an ID for that file. Filenames may contain characters that are not allowed in XML IDs.

These commits make sure that the generated IDs are proper XML IDs.