How Do You Convert XML Records into a Spreadsheet?
XML records turn into a spreadsheet when you flatten each repeating record into a row and map the fields you care about into columns. If you want a fast path, try our free XML to CSV tool and feed it the file directly instead of hand-editing tags in a panic.
The core job is simple: take structured XML, decide what counts as one record, and export the result as CSV so Excel, Google Sheets, or LibreOffice can open it cleanly. The messy part is deciding what to do with nested nodes, repeated groups, missing fields, and attributes that were clearly added by someone who enjoyed making future-you suffer.
What XML to CSV conversion actually does
XML is hierarchical. CSV is flat. That means the conversion is not a literal format swap; it is a decision about how to represent tree-shaped data in rows and columns.
A good conversion usually starts with a repeating parent element, like <record>, <item>, or <row>. Each parent becomes one CSV row, and the child elements become columns such as name, email, status, or created_at.
If your XML has attributes, you can treat them like extra fields. For example, <user id="42" role="admin"> might become columns named id and role, while the element body becomes another column.
The only rule that really matters is consistency. If one record has a field and another does not, the CSV should still keep the column and leave the cell empty, not invent new structure halfway through the file.
How to flatten nested XML without losing useful data
Nested XML is where most conversions get awkward. A purchase order might contain customer details, shipping info, and a list of line items. A spreadsheet can handle the first two in one row, but the line items want their own rows or their own joined text field.
You generally have three options:
- Flatten nested fields into dotted column names, like
customer.nameorshipping.city. - Split repeating child nodes into separate rows, one row per child item.
- Serialize repeated values into one cell, such as a pipe-separated list.
The right answer depends on what you plan to do next. If the CSV is for reporting, flattening dotted fields is often enough. If it is for import into another database, you may want one CSV for parents and another for children.
Be careful with repeated nodes that appear multiple times under the same parent. A single row cannot represent two addresses or five order items without some kind of compromise, so decide early whether you want to duplicate the parent row or extract the nested data into a separate table.
If you are dealing with messy text inside nodes, our guide on how structured data gets reshaped into XML is a useful mirror image of the same problem: choosing a shape before you move data around.
Pick the record boundary first
The most important conversion decision is the record boundary. In plain terms: which element represents one row?
For a product catalog, it might be <product>. For API responses, it might be <item> buried inside a response wrapper. For logs, it might be <event>. Once you know that, the rest of the mapping gets much easier.
Here is a practical way to think about it:
- Wrapper elements like
<response>,<feed>, and<data>usually do not become rows. - Repeating siblings usually do become rows.
- Leaf nodes usually become columns.
If the XML was generated by a system you do not control, inspect a few samples before converting anything at scale. Some XML looks flat at first glance, then hides a nested structure two levels down like a trapdoor in a server room.
Handling dates, IDs, and other fields that need cleanup
XML to CSV conversion often exposes data that benefits from normalization. Timestamps may arrive in ISO 8601, epoch seconds, or some custom format from a legacy system that refuses to retire.
If your XML stores Unix timestamps, it can help to convert them before or after export so the sheet is readable without formula gymnastics. For that kind of cleanup, use our Unix Time converter when the raw number is less helpful than the actual date.
IDs, URLs, and email addresses are also common cleanup targets. A tag like <contact>sam@example.com</contact> is fine, but sometimes the content mixes several values in one field. In those cases, tools like the URL extractor or email extractor can help split out values that deserve their own columns.
Watch for encoding issues too. XML may contain escaped characters such as &, <, or newline entities. CSV exports should preserve the meaning of the text while keeping commas, quotes, and line breaks properly escaped for spreadsheet software.
Spreadsheet rules that matter after export
Once the file is CSV, spreadsheet apps impose their own rules. Commas inside fields need quotes. Quotes inside fields need doubling. Newlines inside fields need to stay wrapped inside the cell instead of exploding the row count.
That means the export has to be valid CSV, not just comma-looking text. A field like "ACME, Inc." should stay one cell, and a multiline note should be quoted so the row still loads correctly.
Also pay attention to column order. Put stable identifiers first, then human-friendly labels, then optional metadata. A decent default order makes the file easier to scan and easier to diff in version control.
If you are preparing data for repeat import, consider whether a second pass is needed. Sometimes the XML-to-CSV step is only the first half; the next step is filtering, reordering, or splitting columns before the data is actually useful.
A Worked Example
Here is a small XML sample and the kind of CSV output you usually want from it.
<orders>
<order id="1001" status="paid">
<customer>
<name>Ava Chen</name>
<email>ava@example.com</email>
</customer>
<total currency="USD">49.90</total>
<created_at>1714586400</created_at>
</order>
<order id="1002" status="pending">
<customer>
<name>Noah Patel</name>
<email>noah@example.com</email>
</customer>
<total currency="USD">19.00</total>
<created_at>1714672800</created_at>
</order>
</orders>A flat CSV representation could look like this:
id,status,customer.name,customer.email,total,total.currency,created_at
1001,paid,Ava Chen,ava@example.com,49.90,USD,1714586400
1002,pending,Noah Patel,noah@example.com,19.00,USD,1714672800If you want the timestamps readable, convert created_at into a normal date after export. If you want to keep the line items from a more complex order file, those would usually belong in a separate CSV with one row per item, linked back to order_id.
Now compare that with a nested order structure that includes multiple items:
<order id="1003" status="paid">
<customer>
<name>Mina Torres</name>
</customer>
<items>
<item sku="A12">
<name>Keyboard</name>
<qty>1</qty>
</item>
<item sku="B55">
<name>Mouse</name>
<qty>2</qty>
</item>
</items>
</order>For this structure, one CSV row is usually not enough if you want each item preserved cleanly. The common fix is a child table:
order_id,customer.name,item.sku,item.name,item.qty
1003,Mina Torres,A12,Keyboard,1
1003,Mina Torres,B55,Mouse,2That is the point where XML to CSV stops being a file-format task and becomes a modeling task. You are deciding how the data should live in a spreadsheet, not just pressing a conversion button.
Frequently Asked Questions
Can XML be converted directly to CSV?
Yes, if the XML has a repeating structure that maps cleanly to rows and columns. Flat record-style XML is easy to convert, while deeply nested XML usually needs a flattening rule first. The conversion works best when each row has one clear parent element.
What happens to nested elements during XML to CSV conversion?
Nested elements are usually flattened into extra columns or split into a second table. If the nesting is repeated, one CSV row often cannot represent it without duplication or loss. The safest approach is to decide whether the nested data belongs in the same row or a related CSV.
How do I keep XML attributes when exporting to CSV?
Map attributes to their own columns, usually alongside the element text. For example, <total currency="USD">49.90</total> can become total and total.currency. The exact column name is less important than keeping it consistent across every row.
Why does my CSV look broken in Excel after converting from XML?
Usually the export did not escape commas, quotes, or line breaks correctly. Excel expects valid CSV quoting, so a comma inside a field must be wrapped in quotes. If the data still looks wrong, check the delimiter, the file encoding, and whether the XML produced multi-line values.
Wrapping Up
XML to CSV is mostly about flattening structure without throwing away meaning. The trick is to pick the right record element, decide how to handle nested data, and keep the output valid enough for spreadsheet software to open without a fight.
If the XML is clean and regular, the conversion is straightforward. If it is nested, mixed, or full of attributes and timestamps, a little modeling goes a long way before export.
When you are ready to turn the file into something a spreadsheet can actually use, give the XML to CSV tool a spin and see how the structure shakes out.