The characterization of nanostructured surfaces with sensitivity in the sub-nm range is of high importance for the development of current and next-generation integrated electronic circuits. Modern transistor architectures for, e.g., FinFETs are realized by lithographic fabrication of complex, well-ordered nanostructures. Recently, a novel characterization technique based on X-ray fluorescence measurements in grazing incidence geometry was proposed for such applications. This technique uses the X-ray standing wave field, arising from an interference between incident and the reflected radiation, as a nanoscale sensor for the dimensional and compositional parameters of the nanostructure. The element sensitivity of the X-ray fluorescence technique allows for a reconstruction of the spatial element distribution using a finite element method. Due to a high computational time, intelligent optimization methods employing machine learning algorithms are essential for timely provision of results. Here, a sampling of the probability distributions by Bayesian optimization is not only fast, but it also provides an initial estimate of the parameter uncertainties and sensitivities. The high sensitivity of the method requires a precise knowledge of the material parameters in the modeling of the dimensional shape provided that some physical properties of the material are known or determined beforehand. The unknown optical constants were extracted from an unstructured but otherwise identical layer system by means of soft X-ray reflectometry. The spatial distribution profiles of the different elements contained in the grating structure were compared to scanning electron and atomic force microscopy and the influence of carbon surface contamination on the modeling results were discussed. This novel approach enables the element sensitive and destruction-free characterization of nanostructures made of silicon nitride and silicon oxide with sub-nm resolution.