IMPORTXML in Google Sheets: XPath Queries and Locale
Extract structured data with IMPORTXML in Google Sheets, use verified XPath examples, understand the optional locale argument and troubleshoot missing nodes and external access.
Verification status: See the evidence and test scope described in this guide. How formula examples are checked
Quick answer: =IMPORTXML("https://www.w3schools.com/xml/note.xml","/note/heading") is expected to return Reminder for the inspected public XML file. The XPath selects one named element from the source.
Syntax and the optional locale
=IMPORTXML(url, xpath_query, [locale])
The individual Google IMPORTXML reference documents a URL, an XPath query and a language/region locale for parsing. When locale is omitted, the document locale is used.
The individual page displays three arguments without bracket notation, but its prose explicitly describes omitted locale and its examples use two arguments. The syntax above reflects that optional behavior. A shorter catalog entry should not be treated as proof that the third argument does not exist.
This guide’s examples select ordinary text and omit locale. A complete accepted-locale-code list and detailed numeric/date coercion rules were not established by the reviewed page; no unverified locale spelling or conversion result is assumed.
Worked example: select fields from a small XML document
Put this public source URL in Setup!A1:
https://www.w3schools.com/xml/note.xml
The file is linked from the publisher’s XML examples page. In separate clear cells, enter:
=IMPORTXML(Setup!A1,"/note/to")
=IMPORTXML(Setup!A1,"/note/from")
=IMPORTXML(Setup!A1,"/note/heading")
Expected values for the retrieved October 17, 2026 snapshot are Tove, Jani, and Reminder, respectively. The source has a note root containing those named child elements.
The results were independently checked by parsing the actual XML. They are source-based expectations rather than observations from a native Sheets import. If the publisher changes the file, a correct formula can return different text later.
Understand the path before changing it
The W3C XPath specification defines location paths for selecting document nodes. In /note/heading, the initial slash starts at the document root, and each following name identifies a child step.
A broad expression such as //heading searches for matching descendant elements rather than spelling out the entire path. For this simple fixture, both paths identify the same single heading. On a larger document, the broader version could match several unrelated sections.
An XPath query is not a CSS selector, a search-engine phrase or a formula to run on the destination cells. Quotes belong around the query string in the spreadsheet formula. Use single quotes inside the XPath when that makes nested quoting easier.
Advanced application: filter a particular HTML table row
IMPORTXML also supports structured HTML according to Google. Put this separately inspected page URL in Setup!A2:
https://www.w3schools.com/html/html_tables.asp
Use:
=IMPORTXML(Setup!A2,"//table[@id='customers']//tr[td[3]='Germany']/td[1]")
Expected value for the inspected source: Alfreds Futterkiste. The independent HTML parser found exactly one row matching this query.
Read the expression in parts:
table[@id='customers']restricts the search to a table with that ID.//trfinds rows inside it, including rows beneath an intermediate grouping element.[td[3]='Germany']retains rows whose third data cell has that text./td[1]selects the first data cell from each retained row.
XPath positions start at 1 in these predicates. The filter is based on source structure and exact text; changing column order or adding whitespace to the source can require revisiting the query.
An ID-based selection can be more targeted than asking for the first table on a page, but it is not immune to redesigns. If the ID disappears, the intended selection no longer exists.
Keep selections small and check their meaning
Google’s import guidance recommends narrowing an XPath query when the result is too large. Selecting every link or every text node can import navigation, footers and unrelated content as well as the material you wanted.
A useful test is to select one known field, compare it with the raw source, and then expand the query deliberately. Preserve the source URL and inspection date alongside an important extracted value so later changes can be investigated.
The W3C specification explains XPath syntax; it does not establish that Sheets supports every function or feature in every XPath version. This guide uses simple location paths, attributes, positional predicates and equality. Exact native handling of namespaces, malformed documents and all complex XPath expressions was not established.
Refresh, errors and external access
Google documents hourly checks for IMPORTXML while the spreadsheet is open. Reloading the browser does not itself force an import refresh. Repeated formula replacement and volatile dependencies can produce unnecessary requests or errors; TODAY is the documented volatility exception.
An editor may need to approve external-data access, and an administrator can block a source. Respect those restrictions rather than trying to disguise the destination. A page visible in an authenticated browser is not automatically fetchable by a spreadsheet function.
If nothing useful appears, check the actual returned document, element names, quotation marks and query scope. Content assembled by browser scripts may not exist in the retrieved source. Avoid silently replacing all failures with blanks, which can hide missing data as though it were a valid empty field.
Availability and verification
IMPORTXML is documented in current rolling Google Sheets. Original introduction date and first or last functioning numbered releases were not established.
NOT_TESTED_IN_GOOGLE_SHEETS. Individual Google help, the W3C XPath reference and both public sources were inspected on October 17, 2026. The XML fields and HTML predicate were independently parsed. No native import, permission grant or screenshot is claimed.