Identification of isomers in the gas phase and as adsorbates by near-edge X-ray absorption fine structure spectroscopy