Exceljet

Quick, clean, and to the point

Parse XML with formula

Excel formula: Parse XML with formula
Generic formula 
=FILTERXML(A1,"xpath")
Summary 

To parse XML with a formula, you can use the FILTERXML function. In the example shown, the formula in D5 is:

=FILTERXML(B5,"//album/title")

which returns the ten album titles in the XML.

Note: FILTERXML is not available in Excel on the Mac, or in Excel Online.

Explanation 

The FILTERXML function can parse XML using XPath expressions. XML is a special text format designed transport data, with features that allow it to be easily parsed and verified by software. XPath is a query language for selecting the elements and attributes in an XML document. The FILTERXML function uses XPath to match and extract data from text in XML format.

In the example shown cell B5 contains XML data that describes 10 music albums. For each album, there is information about the title, the artist, and the year. To parse this XML, the FILTERXML function is used 3 times in cells cells D5, E5, and F5 are as follows:

=FILTERXML(B5,"//album/title") // get title
=FILTERXML(B5,"//album/artist") // get artist
=FILTERXML(B5,"//album/year") // get year

In each case, the XPath expression targets a specific element in the XML. For example, in cell D5, the XPath targets the title element with this string:

"//album/title"

With this XPath expression, FILTERXML returns all 10 album titles. Because this example has been created in Excel 365, which supports dynamic arrays, the results spill into the range D5:D14 automatically.

Author 
Dave Bruns

Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.

Download 100+ Important Excel Functions

Get over 100 Excel Functions you should know in one handy PDF.