We report on the X-ray absorption near edge structure (XANES) and X-ray magnetic circular dichroism (X-MCD) study of Nd2TM17Ax (TM=Co,Fe, A=N,H) materials for novel permanent magnets. Introducing N or H atoms onto interstitial sites increases the Curie temperature of iron compounds and a large increase of magnetocrystalline anisotropy can be achieved with N uptake. In order to study the influence of light elements on the electronic properties of individual elements, an X-MCD study on the Fe,Co:K edge as well as on the Nd:L2,3 edges has been carried out. The XANES spectra on the Fe,Co:K edges show a smoothening of the middle-edge kink with H and N uptake. The effect is much stronger for the nitrides than for the hydrides and is attributed to a higher degree of localisation of Fe,Co 4p band, which is the final state of the K edge transition. The XANES spectra at the Nd:L2,3 edges show a narrowing of the white line with H,N uptake. The effect is much stronger for the nitrides than for the hydrides and denotes a higher degree of localisation of the Nd 5d band which is the final state of the L2,3 transitions. The normalised area of the white line for the nitrides is larger than in other compounds, which is attributed to a lower 5d band filling in the nitrides due to an electron transfer to adjacent nitrogen atoms. A decrease of magnitude of the negative K-edge X-MCD peak with H and N substitution in the cobalt compound is attributed to a decrease of polarization of the 4p band. A lowering of the positive X-MCD signal at the Nd:L2 edge with N uptake denotes a lower spin polarization of 5d3/2 band in Nd2Co17Nx. In iron-based compounds, the X-MCD spectra at Fe:K and Nd:L2,3 edges do not show considerable changes with H or N addition. This can be interpreted as a weak influence of H and N atoms on the 4p and 5d electron polarization, possibly due to larger interatomic distances in the Fe compounds than in the Co compounds.