How to use the FILTERXML function
The FILTERXML function extracts specific values from XML content by using the given xpath. The function was introduced in 2013 and you need Excel 2013 or a newer version to use the FILTERXML function.
Formula in cell B3:
Excel Function Syntax
FILTERXML(xml, xpath)
Arguments
xml | Required. A value in XML format. |
xpath | Required. A value in XPath format. |
Comments
- The FILTERXML returns a #VALUE! error if the XML is not valid.
- The FILTERXML returns a #VALUE! error if the XML contains a namespace with a prefix that is invalid.
What's on this page
1. How to extract XML attribute?
An XML element may contain an attribute, the following formula demonstrates how to extract a given attribute from XML data.
Formula in cell B6:
2. How to import XML data?
- Select a destination cell.
- Go to tab "Developer" on the ribbon.
- Press with left mouse button on the "Import" button, a file dialog box appears.
- Press with mouse on an XML file to select it.
- Press with left mouse button on the "Open" button to import the file.
Here is what the example XML data looks like:
3. Put XML data in different columns based on XML tags?
Formula in cell B6:
Explaining formula in cell B6
Step 1 - Concatenate column header to build xpath arg
"//"&B$5
becomes
"//"&"Europe"
and returns "//Europe"
Step 2 - Extract XML data
FILTERXML($B$3,"//"&B$5)
becomes
FILTERXML($B$3, "//Europe")
becomes
FILTERXML("<countries><Europe>France</Europe><Asia>China</Asia><Europe>Spain</Europe><Asia>Japan</Asia><Asia>Thailand</Asia><Africa>Kenya</Africa></countries>", "//Europe")
and returns {"France";"Spain"}.
'FILTERXML' Function examples
The following 5 articles have formulas containing the FILTERXML function.
Picture above shows cheap chinese IoT modules: a temp sensor and an esp8266-01 (25 mm x 15 mm) Thingspeak […]
This article demonstrates formulas that rearrange values in a cell range to a single column. Table of Contents Rearrange cells […]
This article demonstrates a macro and a formula that allows you to sort delimited data in a cell or cell […]
This article demonstrates formulas and a UDF that searches for values in a table based on concatenated values and returns […]
This blog article describes how to split strings in a cell with space as a delimiting character, like Text to […]
Functions in 'Web' category
The FILTERXML function function is one of many functions in the 'Web' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form