This article explains how to create an XML file from the data in your Excel workbook. XML is a standard text format used to exchange data between programs. Websites, accounting software, databases, and many business applications read and write XML files.
With Excel, you can create an XML file without writing any code. It is the simplest solution, as long as the structure of your XML file stays simple, with few hierarchical levels.
Step 1: Prepare your data
We will use a list of names in an Excel sheet for this example.
Important! Your data must not be in a Table. Excel will create a Table during the XML process.
Step 2: Enable the Developer tab
The XML tools are in the Developer tab. If you do not see this tab in your ribbon, follow this guide: Enable the Developer Tab in Excel.
Step 3: Create the XML mapping file
For us, the structure of the data in Excel is obvious: each row is a person, column A is the rank, and column B is the last name. But for a computer, the raw data in an Excel sheet has no structure at all. You must describe it, and XML needs this description.
This is why you must first build an XML structure. The easiest way is to write only the first two records in a text file, with a text editor like Notepad++. Then Excel will use this structure and apply it to all the other rows of your sheet.
Here is the XML structure for our list of last names:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<list-name>
<record>
<rank>1</rank>
<lastname>Smith</lastname>
</record>
<record>
<rank>2</rank>
<lastname>Johnson</lastname>
</record>
</list-name>Follow these four rules carefully:
- The first line must include the XML declaration.
- The structure must match the Excel columns; values are just examples.
- You must have at least two records. One is not enough for XML export.
- Save the file with the .xml extension.
Step 4: Load the XML mapping file
Now you must load the XML file structure into your Excel workbook.
- Click the Developer tab
- Select Source
- Click XML Maps
- Select the XML file created in step 3
- In the dialog box that opens, click the Add… button
- Then select the XML file that contains the structure you created in step 3.
Now your XML file Excel mapping is loaded.
Step 5: Drag the XML fields
- Just like with a Pivot Table, drag the XML fields to your spreadsheet columns.
- Excel will create a Table.
- The linked fields appear bold in your sheet.
- Repeat this step for each XML field.
Step 6: Export your XML file
Last step: click Developer > XML > Export to convert data into an XML file.
Here is the final result.