Several methods can be used to compensate for the charging. The simplest way is to irradiate the sample additionally with low energy electrons. The positive charges in the sample attract part of these electron. If the current (=number of electrons) and theri energies are correct, then a perfect neutralization is possible. If the current and the energy is too high, then a negative counter charging can occur. A way to avoid this, is to offer additionally positive ions of low kinetic energies. By this a counter charging is avoided. Other ways to neutralize is to increase the sample temperture or irradiation with UV light to generate electron-hole pairs.
The most efficient way is to use residual gas. In NAP-XPS, at pressures equal or above 1 mbar the X-rays ionize the residual gas, producing positive ions and electrons in front of the sample. A self compensation occurs, in case the photon density is not too high. This is true for all laboratory X-ray sources. This procedure is named environmental charge compensation.