When a sample is bombarded with high-energy electrons, X-rays are emitted from the sample. These X-rays have energies characteristic of the elements present in the sample. An X-ray detector measures the energy and intensity of these emitted X-rays, producing a spectrum that can be analyzed to determine the elemental composition of the sample.