How to Convert CSV or Excel to XML with the Right Structure
Turn CSV or Excel rows into well-formed XML: valid element names, attributes or elements, grouping, escaping, empty cells and namespaces explained simply.

Product feeds, accounting imports, government upload portals and many older integrations still ask for XML. Your data, meanwhile, lives in a spreadsheet. The conversion looks trivial until the importer rejects the file because of a column called Unit Price (EUR), an ampersand in a description or a field that should have been an attribute. This guide covers the decisions that matter and how to make them quickly.
Rows, elements and a root
An XML document has exactly one root element. Inside it, each spreadsheet row usually becomes one element, and each column becomes a child element of that row:
<products>
<product>
<sku>TEA-250</sku>
<price>4.50</price>
</product>
</products>
The names products and product are yours to choose. Check the importer's documentation: many feeds require specific names and sometimes a specific order of child elements.
Valid names
XML element and attribute names cannot contain spaces or most punctuation, cannot start with a digit, and should not start with the letters xml, which the specification reserves. A header such as Full Name becomes Full_Name, and 2nd phone becomes _2nd_phone. Rename freely to whatever the target system expects.
Elements or attributes?
Both carry data. Attributes suit short identifiers and codes, for example <product sku="TEA-250">. Elements suit longer text, values that may contain markup, and anything a schema expects as an element. A third option is to make one column the text of the row element itself, as in <name id="7">Alice</name>, which some simple formats use.
Escaping and CDATA
Five characters have special meaning in XML. In text, &, < and > must be written as &, < and >. In attributes, double quotes and line breaks need escaping too. A converter should do this for every value. Some importers prefer HTML descriptions wrapped in a CDATA section instead, which keeps the markup readable. Control characters that XML 1.0 forbids should be removed, or no parser will open the file.
Grouping
Some formats nest records under a category or a customer. Grouping by a column creates one group element per distinct value, such as <category name="Tea">, with the matching rows inside.
Empty cells
There are three reasonable choices: an empty element <description/>, leaving the element out, or an explicit nil marker xsi:nil="true" for schemas that require it. Which one is correct depends on the receiving system.
Doing it step by step
The CSV to XML Converter runs these steps in your browser.
- Open a CSV, TSV or Excel file, or paste CSV. The delimiter is detected.
- Set the root and row element names.
- In the mapping table, adjust each XML name and choose child element, attribute, row text or skip. Tick CDATA for HTML fields.
- Pick a grouping column if the format needs one, and choose how empty cells are written.
- Add a namespace if required, choose the indent, and keep or drop the XML declaration.
- Read the preview of the first rows, fix any warnings, then download the full file.
An example
A small shop sheet has seven columns: sku, name, category, price, currency, stock and description. With sku as an attribute and grouping by category, the file contains a Tea group with two products and a Kitchen group with two more. The description "Strong & malty black tea" is safely written with &, and the text "dishwasher <safe>" no longer looks like a tag. Leaving out empty cells removes the blank description of one product. The file opens without errors in any browser.
What to check afterwards
Well-formed XML is not automatically valid for a particular importer. If the target publishes an XSD schema, validate against it, and compare one record with the sample file in their documentation. Pay attention to decimal separators and date formats: the converter writes values exactly as they appear in your sheet.
Summary
Decide on names, choose elements or attributes per column, let the tool escape everything, and validate against the receiver's rules. The spreadsheet stays the place where people edit data, and XML becomes a quick export.



