In this comprehensive guide, we will explore the FILTERXML function in Excel, which is a powerful tool for extracting specific data from XML content. This function is particularly useful when working with XML data sources, such as web services or XML files. We will cover the syntax, examples, tips and tricks, common mistakes, troubleshooting, and related formulae for the FILTERXML function.


The FILTERXML function has the following syntax:

FILTERXML(xml, xpath)


  • xml is the XML content from which you want to extract data. This can be a string containing XML data or a cell reference containing the XML data.
  • xpath is the XPath expression used to query the XML content and extract the desired data. XPath is a language used to navigate through XML documents and select specific elements, attributes, or values.


Let’s look at some examples of how to use the FILTERXML function in Excel.

Example 1: Extracting data from an XML string

Suppose you have the following XML data in cell A1:



<title>The Catcher in the Rye</title>

<author>J.D. Salinger</author>



<title>To Kill a Mockingbird</title>

<author>Harper Lee</author>



To extract the title of the first book, you can use the following formula:

=FILTERXML(A1, “//book[1]/title”)

This will return “The Catcher in the Rye”.

Example 2: Extracting data from an XML file

Assume you have an XML file named “employees.xml” with the following content:



<name>John Doe</name>




<name>Jane Smith</name>

<position>Assistant Manager</position>



First, you need to import the XML data into Excel using the “Data” tab and “From XML” option. Once the data is imported, assume it is in cell A1. To extract the position of the second employee, use the following formula:

=FILTERXML(A1, “//employee[2]/position”)

This will return “Assistant Manager”.

FILTERXML Tips & Tricks

Here are some tips and tricks to help you get the most out of the FILTERXML function:

  1. When using XPath expressions, remember that they are case-sensitive. Make sure to use the correct case for element and attribute names.
  2. Use the double forward-slash (//) to search for elements anywhere in the XML document, not just at the root level.
  3. If you want to extract multiple values, you can use the “|” (pipe) operator in your XPath expression. For example, to extract the titles and authors of all books in the previous example, use the following formula:

    =FILTERXML(A1, “//book/title | //book/author”)

  4. When working with large XML documents, consider using Excel’s built-in XML mapping feature to create a structured table from the XML data. This can make it easier to work with the data and use FILTERXML to extract specific values.

Common Mistakes When Using FILTERXML

Here are some common mistakes to avoid when using the FILTERXML function:

  1. Using incorrect or invalid XPath expressions. Make sure your XPath expression is valid and properly formatted.
  2. Not properly escaping special characters in your XML data. If your XML data contains special characters, such as “&”, “<“, or “>”, make sure they are properly escaped using their corresponding XML entities, such as “&”, “<“, and “>”.
  3. Trying to use FILTERXML with non-XML data. The FILTERXML function is specifically designed to work with XML data. If you need to extract data from other formats, such as JSON or CSV, consider using other Excel functions or tools.

Why Isn’t My FILTERXML Working?

If your FILTERXML function is not working as expected, consider the following troubleshooting steps:

  1. Check your XML data for errors or inconsistencies. Make sure it is well-formed and properly structured.
  2. Verify that your XPath expression is correct and properly formatted. Test your XPath expression using an online XPath tester or another tool to ensure it is valid and returns the expected results.
  3. Ensure that your XML data and XPath expression are case-sensitive. Double-check the case of element and attribute names in both your XML data and XPath expression.
  4. If you are still having issues, consider posting a question on an online forum or community, such as Stack Overflow or the Microsoft Excel Community, where experts can help diagnose and resolve your issue.

FILTERXML: Related Formulae

Here are some related Excel functions that can be useful when working with XML data:

  1. WEBSERVICE: This function allows you to retrieve data from a web service by providing a URL. You can use this function in combination with FILTERXML to extract data from XML-based web services.
  2. ENCODEURL: This function can be used to encode a URL, making it suitable for use with the WEBSERVICE function. It is particularly useful when your URL contains special characters or spaces.
  3. LEFT, MID, RIGHT: These text functions can be used to extract specific parts of a text string, such as XML data. They can be useful when you need to extract data from XML content that is not well-suited for FILTERXML.
  4. FIND, SEARCH: These functions can help you locate specific text within a larger text string, such as XML data. They can be useful when you need to identify the position of specific elements or attributes within your XML content.
  5. TEXTJOIN: This function can be used to concatenate multiple text strings, such as XML data, with a specified delimiter. It can be useful when you need to combine XML data from multiple sources or cells.

By mastering the FILTERXML function and related formulae, you can efficiently extract and manipulate XML data in Excel, making it easier to work with complex data sources and perform advanced data analysis.


Did you find this article useful?

Share it with your friends or colleagues

About Aepoch Advisors

We are a boutique accounting and consulting firm servicing international businesses operating in China. We offers book keeping and business advisory service. We also help our clients select and implement SAAS business applications
Cloud technology significantly reduces cost foreign companies traditionally spent on tax compliance and ERP systems. Our cloud professionals can help with streamlining your management and controling structure, as well as advising you on how to reduce risks and maximize profits with software purposely built for Chinese business. Contact us today to learn more about our services.