EUComply

How to Convert CSV to XML

September 2026 · 4 min read · Try it in your browser →

Legacy import formats, .NET config, enterprise feeds — plenty of systems still ask for XML when your data starts life as a spreadsheet export. Here's the conversion without hand-building tags.

Option 1: The Transmute CLI (free)

Given people.csv:

name,age,city
Alice,32,Aarhus
Bob,25,Odense
$ npx github:mahope/transmute people.csv --output xml
<?xml version="1.0" encoding="UTF-8"?>
<data>
  <item>
    <name>Alice</name>
    <age>32</age>
    <city>Aarhus</city>
  </item>
  ...
</data>

Because transformation happens before serialization, you can filter and reshape on the way through:

$ npx github:mahope/transmute people.csv     --pipe '[{"op":"filter","expr":"item.age > 26"}]'     --output xml
<?xml version="1.0" encoding="UTF-8"?>
<data>
  <item>
    <name>Alice</name>
    <age>32</age>
    <city>Aarhus</city>
  </item>
</data>

Option 2: Python

import csv
from xml.etree.ElementTree import Element, tostring

root = Element("data")
for row in csv.DictReader(open("people.csv", newline="")):
    item = Element("item")
    for k, v in row.items():
        child = Element(k)
        child.text = v
        item.append(child)
    root.append(item)
print(tostring(root, encoding="unicode"))

Standard library only — but note it does not escape invalid tag names. A header like first name (with a space) produces broken XML unless you sanitize keys yourself.

Things that bite people

Pipelines like this — without writing a script

The Transmute CLI is free (npx github:mahope/transmute). The desktop app adds an interactive pipeline builder, live preview and batch processing — one-time $19, no subscription.

Try the live demo →   See pricing

More guides: JSON to XML · CSV to JSON