On-device AI — professional-grade, fully private.

Documents

CSV to XML: How to Convert a CSV File to Valid XML Online

Convert CSV to XML online for free: map the header row to element names, set root and row tags, fix invalid names, escape values and pick the right encoding.

Updated November 8, 20269 min read

To convert CSV to XML, open the CSV to XML converter, drop your file, name the root element and the row element, check the preview and download. Each row of the CSV becomes one row element, and each column becomes a child element named after the header, or an attribute if you prefer. The part that takes thought is not the conversion itself but the gap between the two formats: a spreadsheet header can be any text at all, while an XML name has strict rules, and characters such as & and < must be escaped. This guide covers how the mapping works, what the settings do and the specific things that break an import.

How a CSV to XML converter maps your columns

Take a three-column file with the header id,city,total and one data row 7,Paris,19.90. With the default settings the result is a root element called root, one element called row per data line, and one child element per column: <root><row><id>7</id><city>Paris</city><total>19.90</total></row></root>. The first line of the CSV is never written out as data; it supplies the names.

CSV partBecomes in XMLSetting that controls it
The whole fileOne root element wrapping everythingRoot element (default root)
Each data lineOne element inside the rootRow element (default row)
Each header fieldThe name of a child element or attributeFirst row as element names
Each cellElement text, attribute value or CDATAWrite columns as, plus per-column overrides
An empty cellAn empty element, nothing, or xsi:nilEmpty cells
No header rowNames column_1, column_2 and so onTurn First row as element names off

Before choosing anything, ask what will read the file. If another system expects a particular shape (say <products><product> with a sku attribute), set the names to match exactly; XML is case-sensitive, so Product and product are different elements and an importer looking for one will not find the other.

Converting CSV to XML, step by step

1

Add the CSV

Open the CSV to XML tool and drop a .csv, .tsv, .txt or .psv file. The delimiter (comma, semicolon, tab or pipe), the quote character and the encoding are detected from the file.

2

Name the root and row elements

Replace root and row with the names the receiving system expects, for example orders and order. If you type a name XML will not accept, the tool warns you and repairs it before use.

3

Choose how columns are written

Under Write columns as, pick Elements or Attributes for the whole file. In the Columns table you can then set any single column to CDATA or Skip, and you can see each header next to the element name that will be used.

4

Decide on empty cells and the declaration

Pick Empty element, Omit or xsi:nil for blank cells, and leave Include XML declaration on unless the receiver asks for a bare fragment.

5

Check the preview and download

The preview shows the first twenty rows built by the same code as the export, with a Well-formed or Not well-formed badge. When it looks right, press Download XML.

Header names that XML will not accept

This is where most hand-made conversions fail. An XML element name must start with a letter or an underscore, and it may not contain spaces, most punctuation or a colon. Names beginning with xml, in any capitalisation, are reserved by the specification. Spreadsheet headers break these rules all the time: Order ID, 2024, -id, Total (£), Unit price/kg. A converter that copies them straight into tags produces a file that every parser rejects on the first line.

Header in the CSVElement name usedWhy
First NameFirst_NameA run of illegal characters becomes one underscore
Total (£)TotalTrailing punctuation is dropped, not turned into underscores
2024_2024A name cannot start with a digit, so an underscore is added
xml or XmlDataPrefixed with an underscoreNames starting with xml are reserved
Name, NameName, Name_2Duplicate names are numbered apart
Führung, 名前UnchangedLetters from any script are legal in XML

The tool repairs every name to the XML naming rules and shows the original header beside the name it used, with a count of how many were renamed, so nothing changes without you seeing it. If the receiving system needs specific names, the cleanest fix is to rename the headers in the CSV itself before converting, because then the file you keep and the XML you send agree.

Root and row names, elements or attributes per column, CDATA, empty-cell rules, indentation and encodings are all free. Free: one file up to 25 MB. Pro: up to 50 files at once in one ZIP, nesting by a column, namespaces and a generated XSD schema. It all runs on your device, not our servers.

Convert CSV to XML

Elements, attributes or CDATA?

Elements are the safe default. <city>Paris</city> can hold text of any length, including line breaks, can be empty, and can carry a type. Choose them when you are not sure.

Attributes put the value on the row itself: <row id="7" city="Paris"/>. The file is noticeably smaller and reads well for short values like ids and codes. Many importers expect ids as attributes and descriptive fields as elements, which is why the default can be overridden per column. One trap: XML parsers replace a raw tab or newline inside an attribute value with a space, so a multi-line address stored as a plain attribute loses its line breaks. This converter writes those characters as references (&#10; for a newline) so the value comes back intact.

CDATA wraps a value so it passes through unchanged, which suits a column holding an HTML snippet. Skip leaves a column out entirely, useful for internal keys that should not travel to the other system.

Escaping: the characters that break XML

Five characters have a special meaning in XML. In element text, & becomes &amp;, < becomes &lt; and > becomes &gt;. Inside an attribute, double and single quotes are escaped as well, as &quot; and &apos;. A product name like Fish & Chips <large> must arrive as Fish &amp; Chips &lt;large&gt; or the file is not well-formed. The converter does this on every value, so you should not pre-escape anything in the CSV; if you do, &amp; turns into &amp;amp; and the receiver shows the code instead of the character.

Some characters cannot appear in XML 1.0 at all, escaped or not: most control characters below the space, such as the NUL byte or the form feed that old database exports sometimes contain. They are removed and the tool reports how many. If that count is large, the source export is probably damaged or in the wrong encoding.

A CSV with broken quoting (a stray quote mark in the middle of a field) can merge several lines into one long cell, and no amount of XML escaping fixes that. Run it through CSV Escape / Fix first, or open it in the CSV viewer to see whether the columns line up.

Encodings and the accents that turn into junk

The XML file is always written as UTF-8, and the declaration line says so: <?xml version="1.0" encoding="UTF-8"?>. The risk is on the way in. If the CSV is read with the wrong encoding, café turns into café or a question mark, and that damage is carried into the XML as if it were real text.

The CSV came from…Encoding to useSign you picked wrong
Most modern apps and online exportsUTF-8 (Auto finds it)é or ’ in place of accents and apostrophes
A Unicode Text export from a spreadsheetUTF-16 LE (a byte-order mark usually decides it)One single column full of gaps
An older Western-European system or a default spreadsheet saveWindows-1252Euro signs and curly quotes become boxes
A file that really is Latin-1ISO-8859-1 (true)Rare; bytes 0x80 to 0x9F are control codes, not quotes

Leave Encoding on Auto-detect first. If the file starts with a byte-order mark, the mark always wins over the dropdown and the tool tells you it ignored your choice. Check a row with accented names in the preview before downloading.

Settings that change what the receiver sees

  • Empty cells: Empty element writes <city></city>, Omit writes nothing, and xsi:nil writes <city xsi:nil="true"/>, the only one that tells a schema-aware system the value is known to be absent.
  • Add xsi:type to elements: labels each value as an integer, decimal, boolean, date, time, dateTime or string, but only when every value in the column fits. A postal code such as 01234 stays a string so its leading zero survives.
  • Indentation: 2 spaces, 4 spaces or a tab for a file people will read; Minified puts everything on one line for the smallest file.
  • Skip leading rows and Comment prefix: drop a title line above the real header, or lines starting with #, so they are not taken as names or data.

If your file is larger than 25 MB, split the CSV by row count and convert the parts, keeping the header on each one. If you are still deciding whether XML is the right target at all, JSON, CSV or XML compares the three formats; for data that is already JSON, use JSON to XML instead.

Frequently asked questions

How do I convert a CSV file to XML for free?

Drop the CSV onto the CSV to XML converter, set the root and row element names, choose elements or attributes, check the twenty-row preview and download the XML. One file up to 25 MB is free, with every setting that affects the XML itself included.

How do I use the CSV header row as XML tags?

Keep First row as element names switched on. Each header becomes the name of a child element, repaired where XML would reject it, for example 2024 becomes _2024. Switch it off and the columns are named column_1, column_2 and so on.

Why does my XML say it is not well-formed?

Usually a tag name that breaks XML naming rules, an unescaped & or < in a value, or a stray control character. The converter repairs names, escapes values and removes illegal characters, so its own output is well-formed. If a file you made elsewhere fails, convert the CSV again here.

Can I make some columns attributes and others elements?

Yes. Set the default under Write columns as, then change any single column in the Columns table to Elements, Attributes, CDATA or Skip. All of this is free.

Why do accented letters look wrong in my XML?

The CSV was read with the wrong encoding. The XML is written as UTF-8, so the damage happened on input. Set Encoding to UTF-8, Windows-1252 or UTF-16 to match how the CSV was saved, and check a row with accents in the preview.

Can I convert several CSV files or create nested XML?

Those are Pro features: up to 50 files at once downloaded as one ZIP, grouping rows under a key column for nested XML, a namespace, and a generated XSD schema. The free version converts one file at a time into flat XML.

Keep reading

More in Documents →