xmlgoogle-sheetsgoogle-sheets-formula

importing from xml to Google Sheets using importxml


I would like to import into Google Sheets the ECB official USD/EUR conversion rates from this link:

https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/usd.xml

But I can't figure out how to phrase the XPATH. I tried this for example:

=importxml("https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/usd.xml", "/CompactData/DataSet/Series/Obs/@TIME_PERIOD")

But I always get "import content is empty". Would appreciate any help, many thanks ahead!


Solution

  • Although I'm not sure whether I could correctly understand your expected values, how about the following formula?

    Sample formula:

    =LET(VALUE_URL,"https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/usd.xml",BASE_XPATH,"//*[local-name()='Obs']/",{IMPORTXML(VALUE_URL, BASE_XPATH&"@TIME_PERIOD"),IMPORTXML(VALUE_URL, BASE_XPATH&"@OBS_VALUE")})
    

    Testing:

    enter image description here