We present a comparison between XANES experiments and full multiple-scattering calculations at the magnesium K-edge for two pyroxenes, diopside and enstatite, for which Mg atoms are only in the M1 site and in two distinct sites M1 and M2, respectively. The influence of the number of octahedral sites per unit cell and of the site distortion on Mg K-edge XANES spectra is investigated. Good agreement between experiment and calculations is obtained. Full multiple-scattering calculations permit identification of the contribution of each site. Comparison reveals that the Mg K-edge spectra of enstatite and diopside M1 sites have the same XANES profile. Cluster size analysis shows that most Mg K-edge XANES features are related to medium range order, i.e., 6 Aa around the absorbing atom. We therefore clearly define the Mg K-edge signature of the geometrical arrangement of atoms around each site, M1 and M2.