X-ray-absorption spectroscopy and n-body distribution functions in condensed matter. I. Theory.