ModernCalcs

XML to CSV Converter

id,name,price,category
1,Widget A,9.99,Tools
2,Gadget B,24.95,Electronics
3,Doohickey C,4.50,Tools

Repeating sibling elements are detected as records. Nested child elements use dot notation (parent.child). XML attributes use @attr prefix.

XML to CSV: Extract Records from XML for Spreadsheet Analysis

Many data exports and feeds use XML with a list-of-records structure — products, orders, users, or transactions wrapped in repeating elements. CSV is what spreadsheets and data pipelines want. This converter detects the repeating record elements, flattens nested children with dot notation, and produces properly quoted CSV ready for import.

Formula
<products> <product> <id>1</id><name>Widget</name><price>9.99</price> </product> <product> <id>2</id><name>Gadget</name><price>24.95</price> </product> </products> → CSV: id,name,price 1,Widget,9.99 2,Gadget,24.95

The converter auto-detects the wrapper element and treats its children as records. Missing fields become empty cells.

Auto-Record Detection

The converter looks at the top two levels of the XML tree: if the root element has a single child type that repeats, those are the records. If the root element is itself a list of record elements, those are used directly. This handles the two most common structures: ... and .......

Dot-Notation Flattening

XML records often have nested child elements:

redL
. The CSV column for color becomes 'details.color' and for size becomes 'details.size'. This matches how pandas and data analysis tools represent nested paths. Very deeply nested structures produce long column names — pre-flatten the XML if column names become unwieldy.

Use Cases for XML-to-CSV

Common conversion scenarios: product catalog XML from a supplier → CSV for import into e-commerce. Order export XML from ERP → CSV for spreadsheet analysis. GIS data in KML (XML) → CSV for latitude/longitude analysis. RSS feed items → CSV for content management. Configuration XML → CSV for bulk editing.

What Gets Converted

  • Repeating record elements → CSV rows
  • Nested child elements → dot-notation columns
  • XML attributes → @attr columns
  • Missing optional fields → empty cells
  • Column union from all records

Frequently Asked Questions

What XML structure works best?

The converter works best with XML that has a clear list-of-records structure: a root element containing repeated child elements (records), where each record has consistent child elements. For example, ....... The converter auto-detects the repeating record element.

How are nested child elements handled?

Nested child elements are flattened using dot notation. A

red
structure produces a column named 'details.color' in the CSV. This makes deeply nested XML addressable as flat columns. Very deep nesting produces long column names.

How are XML attributes handled?

Attributes are included in the CSV with a @ prefix in the column name. For example, produces a '@id' column. If an element has both attributes and child elements, both appear as separate columns.

What if different records have different fields?

The converter uses the union of all fields found across all records as the CSV column set. If some records have a field that others don't, the missing fields appear as empty cells in the CSV. This handles XML where optional elements are omitted for certain records.