In Excel 2021 you can use the built-in functions WEBSERVICE and FILTERXML to retrieve XML data from a web service and then parse it using an XPath expression. For example, if your web service URL returns the following XML:
<products>
<sku>puig_5055C</sku>
<source_price>88.07</source_price>
<rrp_no_tax>176.03</rrp_no_tax>
<currency>EUR</currency>
</products>
You can extract the value of <source_price> by following these steps:
-
Place the Web Service URL in a Cell:
Suppose your web service URL is in cell A1 (e.g., https://example.com/products.xml).
-
Retrieve the XML Data Using WEBSERVICE:
In another cell (say B1), use the formula:
=WEBSERVICE(A1)
This function fetches the XML content from the URL.
-
Parse the XML and Extract the Value with FILTERXML:
In cell C1, use the formula:
=FILTERXML(B1, "/products/source_price")
Here, the XPath expression /products/source_price tells Excel to navigate to the <source_price> node under the root <products> node.
When you enter these formulas, cell C1 will display the extracted value, which is 88.07 based on your XML snippet.
Putting It All Together
If you prefer to write it in a single formula (without using an intermediate cell), you could combine the two steps like this:
=FILTERXML(WEBSERVICE("https://example.com/products.xml"), "/products/source_price")
Replace "https://example.com/products.xml" with the actual URL of your web service.
This setup works well in Excel 2021 and lets you dynamically fetch and parse XML data directly within your workbook.