The field of applied physics is driven by the need to understand materials structure and electronic properties with the ultimate goal of harnessing them in functional devices such as nonvolatile memories. One needs to understand the mechanism, which dictates the behavior of the charged defects and electrons under external stimuli such as electrostatic potential, thermal gradient and photons, to obtain a more microscopic understanding of the system. Then, one arrives at a predictive description of designing functional devices. In the first part of the talk, we report the x-ray-induced reversible resistance change in 40-nm-thick TiO2 films sandwiched by Pt top and bottom electrodes, and propose the physical mechanism behind the emergent phenomenon. Our findings indicate that there exists a photovoltaic-like effect, which modulates the resistance reversibly by a few orders of magnitude, depending on the intensity of impinging x-rays. We found that this effect, combined with the x-ray irradiation induced phase transition confirmed by transmission electron microscopy, triggers a non-volatile reversible resistance change. Understanding x-ray-controlled reversible resistance changes can provide possibilities to control initial resistance states of functional materials, which could be useful for future nonvolatile memories. In the second part, we cover the investigation of Ta2O5 powder and oxygen deficient thin films using synchrotron x-ray studies at the Advanced Photon Source, combining x-ray diffraction, extended x-ray absorption fine structure (EXAFS) and resonant x-ray scattering spectroscopy (RIXS) and Ab initio band structure calculations. Ta-based resistive switching devices have been extensively investigated due to their fast switching and reliable endurance among other materials. Despite extensive recent interests, however, there is still lack of fundamental understanding of electronic structure and local structure of the Ta-based device. Oxygen vacancies play essential roles in the electric functionality of resistive switching devices, which is based on the formation and rupture of conducting paths within the insulating matrix. We found that there are strong correlations among oxygen vacancy number and positions and energy gaps. Ab initio band structure calculations successfully explain the evolution of the electronic excitation spectrum as a function of oxygen vacancy number and positions and importantly provide a predictive description of the oxygen deficient Ta oxide that may improve the desired performance based on atomic level design rather than the traditional trial-error methods.