X-ray absorption near-edge structure (XANES) and x-ray emission spectroscopy (XES) measurements were used to investigate the effect of Mg doping in ZnO nanorods. The intensities of the features in the O K-edge XANES spectra of Zn1−xMgxO nanorods are lower than those of pure ZnO nanorods, suggesting that Mg doping increases the negative effective charge of O ions. XES and XANES spectra of O 2p states indicate that Mg doping raises (lowers) the conduction-band-minimum (valence-band-maximum) and increases the band gap. The band gap is found to increase linearly with the Mg content, as revealed by photoluminescence and combined XANES and XES measurements.