Total concentrations of As, Zn, Pb and Cr were determined in soil samples by using X-ray fluorescence spectrometry. The instrument applicability was good by analyzing the detection limit and accuracy of the instrument. Then, the energy rangesand variable numbers of heavy metal elements were obtained by using two-dimensional correlation spectroscopy. The variable numbersof Pb (10.380 similar to 10.740 and 12.435 similar to 12.900 keV), As (10.380 similar to 10.740 and 11.610 similar to 11.880 keV), Cr (5.310 similar to 5.520 and 5.805 similar to 6.015 keV) and Zn (8.520 similar to 8.805 and 9.555 similar to 9.630 keV) were 57, 44, 30 and 26, respectively. Finally, X-ray fluorescence spectrometry analysis models for heavy metal elements were established based on selected energy ranges by using partial least-squares regression. The results showed that the model performance was best for As, followed by Pb, Zn and Cr, and R-p, were higher than 0.92. The study indicated that the prediction performance of model is improved using optimal energy ranges and the PXRF analyzer is suitable for in-situ monitoring of heavy metals in soil.