Preserving accidentals when changing tonality system

Is there a way to preserve accidentals when changing the tonality system?

I want to import an XML file with music written in 31-EDO with standard accidentals: (double-)sharps, (double-)flats, naturals. When I insert the key signature for the 31-EDO tonality system it strips away all the accidentals.

You could try setting the Preferences>MusicXML Import>Accidental Visibility option?

Accidentals in Dorico are not just visual. The double-flat defined in 12-EDO means specifically 2/12 EDO (200 cents) flattened, and when you change to another tonality system that doesn’t have a 200-cent accidental, it is no longer displayed – although you’ll notice it still plays back as originally notated!

So unless XML has a way to define actual pitch deltas for accidentals, there is no way to just import those accidentals with the intended meaning. You’ll have to redo all the accidentals in a proper 31-EDO environment.