Skip to content
cliplimeClipLime

Convert CSV to XML

Paste a CSV or drop a file and get XML, with your own root and row names and valid element names from any header.

Runs on your device, nothing is uploaded

Convert from

to

Paste, type, drop a file here or load one.

0 characters, 0 lines

Options

When off, columns are called column1, column2 and so on.

Columns such as address.city become nested objects, and tags.0, tags.1 become a list.

XML attributes

Keys that start with this become attributes.

Indentation

More options

The dot in address.city.

Empty cells do not create a key.

Starts the file with <?xml version="1.0"?>.

At a glance

Input
CSV or TSV text or a file. Commas, semicolons, tabs and pipes are detected, and quoted values, doubled quotes and line breaks inside cells are handled.
Structure
Every row becomes an item element and every column a child element named after its header. The root is called root and each row item, and you can rename both.
Names
Headers that are not valid XML names are repaired: first name becomes first_name and 1st becomes _1st. A note says how many were changed.
Attributes
Start a header with @, such as @id, and its value becomes an attribute of the row element. A column named #text becomes the text of the row element.
Nesting
Headers such as address.city become nested elements and tags.0, tags.1 become repeated tags elements. You can turn that off.
Values
Everything is written as text exactly as it is in the CSV, so 007 and 1.50 stay as they are. XML has no types.
Privacy
Your CSV is converted in your browser tab and never uploaded.

How to do it

  1. 1

    Add your CSV

    Paste it, drop a file on the input box, or press Load a file. Example fills in a small CSV with quotes and a line break inside a cell.

  2. 2

    Check the delimiter and the header

    The delimiter is detected. If the guess is wrong, set Delimiter in the input. Keep First row has the column names on if the first row is a header, because those names become the element names.

  3. 3

    Name the elements

    Set the Root element name and the Name of each row element. Choose whether columns that start with @ become attributes, and whether dotted headers become nested elements.

  4. 4

    Copy or download

    Press Copy, or Download to save an .xml file. The notes under the result list any headers that were repaired.

How a table becomes a tree

A CSV file is a flat table. XML is a tree with exactly one root, so the converter adds the root and puts each row in its own element. With the header id,name,city, the row 1,Ana,Lisbon becomes <item><id>1</id><name>Ana</name><city>Lisbon</city></item>, inside <root>. The columns keep their order.

Empty cells become empty elements such as <notes/>. Turn on Leave out empty cells under More options to leave the element out, which makes the file smaller when many cells are blank. Without a header row, switch off First row has the column names and the elements are called column1, column2 and so on.

Turning headers into valid element names

XML names must start with a letter or an underscore, and may contain letters, digits, hyphens, dots and underscores. They cannot contain spaces. The converter repairs only what it must:

  • first name becomes first_name, and a/b becomes a_b.
  • 1st becomes _1st, and a year such as 2022 becomes _2022.
  • é and 名前 stay as they are, because XML names may use letters of any alphabet.
  • A repeated header such as name,name is renamed name, name_2 when the CSV is read, and a blank header is called column2 after its position.

Attributes, nested elements and text

XML offers a choice that CSV does not: a value can be an element or an attribute. By default every column becomes an element. Start a header with @ to make an attribute: with the headers @id,name, the row A1,Ana becomes <item id="A1"><name>Ana</name></item>. A column called #text holds the text of the row element, so @id,#text gives <item id="A1">hello</item>.

Dots build nesting. address.city and address.zip become <address><city>...</city><zip>...</zip></address>, and numbered headers tags.0 and tags.1 become repeated <tags> elements. If your headers contain dots for another reason, such as price.eur, turn off Rebuild nested values from column names, or choose another separator under More options. The elements are then called price.eur, which is a valid XML name.

Pick name instead of @name under XML attributes to treat every column as an element. A leading @ is then replaced with an underscore.

What XML does with your text

  • No types. Numbers, dates and true or false stay as the exact text in the CSV.
  • Escaping. The characters XML reserves are escaped: & becomes &amp;, < becomes &lt;, and quotes become &quot; and &apos;. Any XML reader turns them back into the original characters.
  • Line breaks. A line break inside a quoted CSV cell is kept inside the element. In a column that becomes an attribute it is written as &#10;, which an XML reader turns back into a line break.
  • Forbidden characters. A few control characters that XML 1.0 does not allow are removed, with a warning.
  • Declaration. The file starts with <?xml version="1.0" encoding="UTF-8"?>, which you can switch off under More options.

Questions people ask

How do I make attributes instead of elements?

Start the header with @. A column called @id becomes the attribute id on each row element. A column called #text becomes the text of the row element. Under XML attributes you can switch this off.

Can I change root and item?

Yes. Set Root element name for the outer element and Name of each row element for the element that wraps every row. Names that are not valid in XML are repaired with underscores.

My headers have spaces or start with a digit. Will it work?

Yes. Spaces and punctuation are replaced with underscores and a name that starts with a digit gets an underscore in front, so first name becomes first_name and 1st becomes _1st. A warning shows one example.

How are empty cells written?

As empty elements such as <notes/>. Turn on Leave out empty cells under More options to omit the element completely.

Can I convert a file with semicolons or tabs?

Yes. The delimiter is detected from the first rows, comma, semicolon, tab or pipe, and you can set it yourself under Delimiter in the input if the guess is wrong.

Is my CSV uploaded?

No. The file is read and converted in your browser tab, so private data stays on your device.