Measurements of X-ray emission and absorption of the constituents of MgB 2 are presented. The results obtained are in good agreement with calculated X-ray spectra, with dipole matrix elements taken into account. The comparison of X-ray emission spectra of graphite, AlB 2, and MgB 2 in the binding energy scale supports the idea of charge transfer from σ to π bands, which creates holes at the top of the bonding σ bands and drives the high-Tc superconductivity in MgB 2.