The number density profiles of elements N and O in the altitude range of 120–250 km are retrieved by simulation based on X-ray occultation. Based on the parameters of the NICER telescope, the energy spectrum forward model of the Crab Nebula in the energy range of 0.25–8 keV during the occultation is constructed, and the energy spectrum simulation data are obtained by adding noise to the energy spectrum forward model at different tangent point altitudes. The NICER energy band includes the K-shell absorption edges (0.4 keV, 0.53 keV for N, O), and there are significant differences in X-ray cross sections at the K-shell absorption edges, which provides an opportunity to retrieve the atmospheric density of each element. The MCMC algorithm is used to fit the energy spectrum forward model and simulation data, and the density profiles of elements N and O are retrieved. It is found that the retrieved error of O element in the altitude range of 120–140 km is large, which may be related to the low proportion of O in the line of sight and the low signal-to-noise ratio of simulation data. In the altitude range of 140–200 km, the retrieved error of elements N and O is small, but in the altitude range of 200–250 km, the retrieved error of elements N and O becomes larger, and the inconsistency between the retrieved results and NRLMSISE-00 model values increases. This is because the number of absorbed photons is reduced due to the thin atmospheric density at higher altitude, which introduces great uncertainty into the retrieved results. This study lays a foundation for element density retrieval based on X-ray occultation measured data in the future.