6 min read
Excel to XML: build an XML file from a template
By Quentin Delepierre, Salesforce Commerce Cloud consultant
"Converting Excel to XML" only makes sense with a target format: the same table can become a thousand different XML files, and the system that imports yours accepts only one. ExcelifyXML doesn't guess that format: it reads it from a template XML, a sample of the expected file, then writes your data in that shape. Here is the method, what you need, and its limits.
Got your own XML? Drop it in and see it as a table, free and with no account. For an Excel file you can edit and then rebuild into an XML that keeps its structure, a free account is all you need.
Simple Excel table, free with no account, for files up to 1 MB. File that rebuilds into XML: free account, 3 free credits, no credit card.
How do I convert an Excel file to XML?
You first need a template XML, a sample of the expected file: the same table can become a thousand different XML files, and ExcelifyXML doesn't guess the format. Transform the template to get an Excel file (.xlsx) with the right columns, paste your data into it, save, then drop the file on the Rebuild page: you get an XML file of the same shape as the template. The template's preview is free and needs no account; the transformation costs 1 credit with a free account, and the rebuild is free.
What do you need to convert an Excel file to XML?
- Your data in a spreadsheet (Excel, Google Sheets, LibreOffice), one record per row: a product, a URL, a price.
- A template XML: a sample of the expected file, with at least two records and every field you need. The safest is an export of a few records from the system that will import the file (Business Manager, Magento, PrestaShop…), or the sample given in the target platform's documentation.
- A free ExcelifyXML account: transforming the template costs 1 credit, reconstruction is free and unlimited.
Why do you need a template XML to go from Excel to XML?
A table is flat; an XML file has a structure: a root element, nested tags, attributes, namespaces (g:), sometimes a header. None of that is in your Excel columns.
The template brings that structure. ExcelifyXML draws from it the columns to fill, in an Excel file (.xlsx) or a data.csv, and the structure used to write your XML: skeleton.json, which the Excel file keeps in a hidden sheet.
What are the steps to build an XML file from Excel and a template?
- Drop your template XML on the Upload page. In the free preview, check there's one record per row (a product, a URL…). If it shows a single row, pick the record's tag through "Not the right row?" (item in a Google Shopping feed). Confirm (1 credit) and choose the Excel file (.xlsx) — or the CSV, in a bundle to unzip: data.csv and skeleton.json.
- Open the Excel file (or data.csv). The first line names each column: keep it, and delete the template's rows.
- Paste your data column by column, under the right name. An empty cell creates no tag. For a field the template doesn't have, add a column named after the tag, with its prefix if it has one (g:color): the tag is created at the end of each record. A name that can't be a tag's (one with a space, say) stops the rebuild, which points it out.
- Save. With the Excel file, drop it alone on the Rebuild page: you get your XML back, with no separator or encoding to guess (with Numbers, which removes the hidden sheet, drop it with the template's skeleton.json, in "Separate files"). With the CSV, save as "CSV UTF-8": it's the format that guarantees your accented characters are read correctly, especially when the template has none. With Excel for Mac's plain "CSV" or "CSV (MS-DOS)", the reconstruction usually recognizes the encoding from your letters, or stops and asks for "CSV UTF-8"; but values may still be misread without a warning, whatever the size of the file: a single accented value, between one time in five and half the time depending on the words; text in languages other than French, still one time in five to ten in a file typed entirely. On the Rebuild page, choose "Separate files" and drop this data.csv with the template's skeleton.json: you get your XML back.
An example: a Google Shopping feed
The template has two products. Their rows are replaced with three products from the spreadsheet, and a g:color column is added. The feed's title, link and description come from the template.
<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">
<channel>
<title>Ma boutique</title>
<link>https://www.exemple.fr</link>
<description>Flux produits</description>
<item>
<g:id>MODELE-1</g:id>
<title>Exemple 1</title>
<g:price>1.00 EUR</g:price>
<g:availability>in_stock</g:availability>
</item>
<item>…</item>
</channel>
</rss>g:id , title , g:price , g:availability , g:color
SKU-1 , Veste , 59.90 EUR , in_stock , bleu
SKU-2 , Pull , 39.90 EUR , ,
SKU-3 , Chemise , 29.90 EUR , out_of_stock , vert <item>
<g:id>SKU-1</g:id>
<title>Veste</title>
<g:price>59.90 EUR</g:price>
<g:availability>in_stock</g:availability>
<g:color>bleu</g:color>
</item>
<item>
<g:id>SKU-2</g:id>
<title>Pull</title>
<g:price>39.90 EUR</g:price>
</item>What does the template decide in the resulting XML?
- Everything outside the rows (root element, namespaces, feed title, catalog header) is taken from the template as is: fix it in the template XML before transforming it.
- Each record follows the template's shape: same tags, same order; added columns come last.
- Lists within a record (several images, several prices): a list of simple values fits in one cell, one value per line, and you add as many lines as you need. A list of elements that carry attributes or sub-tags (or any list, if you uncheck “Group repeated values” when uploading) uses the template's numbered columns: image[0], image[1]… A numbered column added beyond them can't be written: the rebuild stops and points it out. Pick a template where one record has the largest number of items then.
- With the CSV, keep EAN and GTIN codes as text when you paste them into Excel, otherwise it turns them into scientific notation. The Excel file (.xlsx) is in Text format: what you type in it stays text.
- The file follows the template's shape, not a schema: have it validated by the system that imports it, on a test environment first.
And next time?
Keep the Excel file (or data.csv and skeleton.json). For the next delivery, update the rows and rebuild: no need to transform the template again, nor to spend a credit.
Turn your template XML into a file to fill:
Transform a file