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 namebecomesfirst_name, anda/bbecomesa_b.1stbecomes_1st, and a year such as2022becomes_2022.éand名前stay as they are, because XML names may use letters of any alphabet.- A repeated header such as
name,nameis renamedname,name_2when the CSV is read, and a blank header is calledcolumn2after 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
&, < becomes<, and quotes become"and'. 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
, 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.