Using IMPORTXML function to extract currency prices in Google Sheets

I’m trying to get a specific value from an XML file into my Google Sheets using the IMPORTXML function. I’m interested in the Forex Selling price for the USD/TRY currency pair, which is shown as 2.9161 in the relevant column.

I’ve tried two different methods, but neither worked out:

=IMPORTXML("https://www.tcmb.gov.tr/kurlar/201511/30112015.xml","/Currency CrossOrder[0]/ForexSelling")
=IMPORTXML("https://www.tcmb.gov.tr/kurlar/201511/30112015.xml","/html/body/div/div/table[1]/tbody/tr[2]/td[5]")

In the second method, I used the inspect tool to copy the full xpath after highlighting the value 2.9161.

I’m expecting the value 2.9161 to appear in my sheet. What might be wrong with my xpath syntax?

It appears you’re mixing XML and HTML, which is causing the issues with your second xpath since it’s trying to target div and table elements that do not exist in an XML context.

As for your first method, the xpath syntax seems incorrect. Remember that XML is case-sensitive. Try using //Currency[@CrossOrder='0']/ForexSelling instead. The double slash allows you to search the entire document, and it handles the attribute selector correctly.

Make sure to check if CrossOrder is indeed an attribute or a separate element in the raw XML. Also, if there are any namespace declarations in the XML file, you’ll need to adjust your xpath accordingly.

your xpath syntax is off. try =IMPORTXML("https://www.tcmb.gov.tr/kurlar/201511/30112015.xml","//Currency[@CrossOrder='0']/ForexSelling") instead. use double slashes for full doc search and proper attr syntax with @. also, check if that xml link still works - tcmb changes their urls sometimes.

Your xpath expressions need fixing to navigate the XML structure properly. The first attempt fails because you’re using wrong syntax for attributes and elements. Try //Currency[@CrossOrder="0"]/ForexSelling or just //Currency[1]/ForexSelling for the first Currency element. I’ve hit similar issues with TCMB’s XML feeds. The attribute names or element positions often don’t match what you’d expect. Load the XML URL directly in your browser first to check the actual structure. You might find the currency data’s nested differently or there are namespaces involved. What worked for me was using //Currency[@Kod="USD"]/ForexSelling to target USD specifically by its code attribute. It’s way more reliable than position-basedselectors.