7 min read
Slim down a large XML file before transforming it
By Quentin Delepierre, Salesforce Commerce Cloud consultant
A large XML export (a catalog, a product feed, an export from a PIM or an ERP) can exceed the size your plan accepts, or give more columns than Excel keeps. “Prepare your file” removes what you don't edit and gives you back a lighter XML with the same structure, which you then transform. Here is when to use it, the steps, what is kept or removed, its limits and the precaution to take before re-importing.
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.
When to use “Prepare your file”
“Prepare your file” is a free tool, no account needed, that slims an XML file before the transformation. It produces neither a CSV nor an Excel file: it removes what you untick and gives you back a lighter XML with the same structure.
It suits a file that repeats the same element: the products of a catalog, the items of a feed, the orders or customers of an export. Three situations call for it:
- The file is larger than your plan accepts (up to 4 MB on the free plan, up to 30 MB on the Pro plan). Removing the languages or fields you don't edit often makes it much smaller.
- The file would give more than 16,384 columns, Excel's limit. Beyond it, the transformation offers no Excel file (.xlsx), and a CSV opened in Excel would be cut.
- You only edit a few fields (prices, descriptions, translations): a narrower table is easier to review and correct.
Step by step
- Open the “Prepare your file” page and drop your XML file (or click to choose it). This step has no size limit, but the file must be UTF-8.
- The tool reads the file and shows “What the file contains”: the repeated elements it will filter (the “Filtered elements” line gives their number, for example 12,000 <product>) and what it always keeps.
- Up to three panels appear, depending on what the file contains: “Languages”, “Sites” and “Attributes and fields”. Everything is ticked at first. Untick what you don't want to keep.
- To go faster, each panel has its “Untick all” and “Tick all” buttons. To keep only a few fields out of hundreds, click “Untick all” in the fields panel, then tick the ones you want. The “Search a field” box filters the list, and the two buttons then act only on the fields shown.
- Watch the “Columns after transformation (estimate)” counter. It shows “≈ N columns of M” (M is the original file's total), updates at every tick and reminds you of Excel's limit: 16,384 columns. Below, it tells you whether the transformation can offer the Excel file (.xlsx). Aim for a number under the limit.
- Click “Prepare the file”. The “Your file is ready” screen gives the size of the prepared file, the original's size and the number of elements removed. If you change a tick afterwards, prepare the file again.
- Download the result with “Download” followed by its name: the original name completed with “-prepared” (catalog.xml gives catalog-prepared.xml). Or click “Transform this file”: the transformation page opens with the prepared file already selected and its free preview. Transforming needs an account (free). If the browser can't pass the file to the next page, a message says so: download it, then drop it yourself.
Example: keep French and remove one field
A small invented catalog with two products. In the “Languages” panel, untick en; in “Attributes and fields”, untick weight.
- The sku attribute of each <product> is kept, like the rest of the file: the text, the indentation and the order are those of the original file.
- The English tags disappear with their content, and <weight> disappears from both products.
- Unticking a field removes it in every language: unticking description would have removed the descriptions in French and in English.
<catalog>
<product sku="A100">
<name xml:lang="fr">Chemise en lin</name>
<name xml:lang="en">Linen shirt</name>
<description xml:lang="fr">Chemise légère pour l'été.</description>
<description xml:lang="en">Light summer shirt.</description>
<price>49.00</price>
<weight>0.3</weight>
</product>
<product sku="A200">
<name xml:lang="fr">Écharpe en laine</name>
<name xml:lang="en">Wool scarf</name>
<description xml:lang="fr">Écharpe chaude pour l'hiver.</description>
<description xml:lang="en">Warm winter scarf.</description>
<price>35.00</price>
<weight>0.2</weight>
</product>
</catalog><catalog>
<product sku="A100">
<name xml:lang="fr">Chemise en lin</name>
<description xml:lang="fr">Chemise légère pour l'été.</description>
<price>49.00</price>
</product>
<product sku="A200">
<name xml:lang="fr">Écharpe en laine</name>
<description xml:lang="fr">Écharpe chaude pour l'hiver.</description>
<price>35.00</price>
</product>
</catalog>What is always kept, what is removed
- Always kept: each filtered element with its attributes (its identifier, such as id or sku), and everything outside these elements (declaration, root, header…).
- Removed, with their content: unticked fields, and elements in an unticked language (xml:lang attribute) or specific to an unticked site (site-id attribute). A container without attributes left with nothing is removed too.
- The rest is copied unchanged: text, CDATA, comments, entities, attribute order, indentation.
- An element without site-id (shared by all sites) is kept, and so is an element without xml:lang.
- A field is a direct child of the filtered element: it is kept or removed whole, with everything it contains. One exception: in a Salesforce B2C Commerce export, custom-attributes and page-attributes are opened up, with one field per attribute.
Languages, sites: what the tool recognises
The “Languages” and “Sites” panels rely on two attributes only: languages are detected only through xml:lang, sites only through site-id (the one in Salesforce B2C Commerce exports, for example). A panel only appears if the file contains at least one value.
- A file that marks the language another way (a lang or locale attribute, a language code in the tag name such as <name_fr>) has no “Languages” panel: only the “Attributes and fields” panel shows, with one box per tag. Untick <name_en>, <description_en>… to remove a language.
- Likewise, without a site-id attribute, there is no “Sites” panel.
- In the transformation's table, a tag repeated in several languages gives one column per language: removing a language cuts the number of columns by as much.
Before you re-import
The prepared file only contains the languages, sites and fields you keep. Depending on the import mode, the platform may erase what is no longer in it.
- Salesforce B2C Commerce (Business Manager): import in MERGE or UPDATE mode. Only the fields present in the file are changed; the others keep their value in the platform (UPDATE does not create objects that don't exist there yet). Do not use REPLACE mode: it erases from the platform what the file does not contain. DELETE mode deletes the objects in the file.
- If your import runs through a job with the replaceCustomAttributes option on, the products' custom attributes that are no longer in the file are erased, even in MERGE or UPDATE mode.
- Other platforms: check in their documentation that a partial import does not empty the fields missing from the file. Keep your original file.
The tool's limits
- UTF-8 only. A UTF-16 file, or an ISO-8859-1 file with accents, is refused with a message that says so: save it as UTF-8, or transform it directly.
- The file must be well-formed XML: an unclosed tag stops the tool, which gives the line.
- No repeated element was found within four levels of the root: there is nothing to filter. You can transform this file as it is.
- The counter is an estimate, made from the transformation's column naming rules: it may differ by a few columns. The exact number shows in the free preview, before any credit.
- The tool removes, it corrects nothing: it renames and reformats no tag.
After the preparation: transform, edit, rebuild
The prepared file is transformed like any file dropped on the transformation page: free preview, choice of the row tag if needed, then Excel file (.xlsx) or CSV. Edit the table, then rebuild the XML on the Reconstruct page (free). That XML only contains what you kept: reread “Before you re-import” before importing it.
Is your file ready? Drop it to see the free preview, no account needed:
Transform a file