<?xml version="1.0" encoding="UTF-8"?>
<xa:MeContext id="ABCe0552553">
<xa:Data id="ABCe05525531" />
<xa:Data id="1" />
<CustID>Cust1234</CustID>
<Name>Smith</Name>
<City>New York</City>
<Orders>
<order Orderid="101">
<Product>MP3 Player</Product>
</order>
<order Orderid="102">
<Product>Radio</Product>
</order>
</Orders>
</xa:MeContext>
This well formed XML document feeds to Excel 2007 using MS VBA code. I was successful
with using DOMDocument and IXMLDOMElement to import the Name, City, and Product.
However, the xa:MeContext id, vsData1 id, VsData2 id, CustID, and order Orderid number won’t export to Excel sheet.
Each Excel row has the following headers with data filled from XML document:
MeContextID--vsData1--VsData2--CustID--Name--City--OrderID--Product--OrderID--Product
Below are two methods to output the fields you need. Note, that the XML you have posted does not contain the header definitions for namespace “xa:” so is not fully formed XML. I’ve removed them in the example so MSXML2.DOMDocument doesn’t throw a parse error.
And the following uses regex, which is really only useful if the XML is fixed to exactly your example each time. It’s not really recommended for parsing XML in general unless you want speed over reliability.
EDIT: Slight update to output to array for writing to range