Blog
← Torna al Blog

Turning Nested XML Data Into a Usable CSV Table

November 03, 2026 1568 words
Turning Nested XML Data Into a Usable CSV Table — guide on Delimiter.site

Your XML export contains every detail you need. Then you open the converted CSV and find missing product codes, duplicated orders, and blank columns with unclear names. The file opens, but the data no longer tells the same story. Turning XML into a useful spreadsheet takes more than replacing tags with commas. You need to decide what each row represents, which details become columns, and how to handle records that have different shapes.

Your Mapping Plan: Choose what one CSV row represents before converting anything. Map element text and attributes to clear column names. Decide whether repeated items need separate rows, extra columns, or a second file. Set a consistent rule for missing values, then check row counts, identifiers, quoting, and spreadsheet imports. Keep the original XML and a record of your choices. A usable CSV preserves the relationships your reader needs, even though its structure is flatter.

Start With What One Row Represents

XML organizes information through parent and child relationships. CSV organizes information into records with the same set of fields. That difference creates the main conversion decision: what does one row mean?

For an order export, a row might represent one order or one purchased item. Both choices can work. They answer different questions. An order report helps you count purchases. An item report helps you total product quantities.

Consider this small source file:

<orders>
  <order id="00127" currency="USD">
    <customer>
      <name>Maya Chen</name>
      <email>[email protected]</email>
    </customer>
    <items>
      <item sku="P10">
        <name>Notebook</name>
        <quantity>2</quantity>
      </item>
      <item sku="P22">
        <name>Pen</name>
        <quantity>1</quantity>
      </item>
    </items>
    <note/>
  </order>
  <order id="00128" currency="USD">
    <customer>
      <name>Luis Ortiz</name>
    </customer>
    <items>
      <item sku="P10">
        <name>Notebook</name>
        <quantity>1</quantity>
      </item>
    </items>
  </order>
</orders>

This file has two orders and three items. A conversion with one row per item should produce three data rows. A conversion with one row per order should produce two. Write down that expectation before running the conversion. It gives you an immediate way to catch lost or multiplied records.

Give Elements and Attributes Clear Column Names

An element usually holds text between opening and closing tags. In the sample, <quantity>2</quantity> provides the value 2. An attribute stores a value inside an opening tag. The order identifier appears as id="00127", while the product code appears as sku="P10".

Both can become CSV columns. Check whether your conversion settings include attributes. A result that captures every product name but drops every product code may look complete until someone tries to match it against an inventory file.

Use names that preserve context. The source contains two elements named name: a customer name and an item name. Calling both columns name creates confusion. Use customer_name and item_name instead.

Keep a simple mapping note beside your export. For example, order/@id maps to order_id, and order/customer/name maps to customer_name. Here, @ marks an attribute in the mapping notation. It does not belong in the exported value.

Some XML files use namespace prefixes, which appear before a colon in element names. If your file contains them, make sure the converter recognizes the namespace relationships. Removing prefixes without checking their meaning can merge fields that belong to different vocabularies.

Choose How Repeated Items Become Flat Data

Repeated child elements need an explicit rule. Taking only the first matching item silently discards information. Joining all values into one cell may preserve readable text, but it can make filtering and calculations harder.

How Repeated Items Change the Output

Approach Result for One Order With Two Items Main Tradeoff
One row per item Two rows with the order identifier repeated Easy item analysis, but order totals can be counted twice
Numbered item columns One row with item_1 and item_2 fields Readable for small fixed limits, awkward when item counts grow
Joined values One row containing a list inside a cell Compact, but individual values need further parsing
Separate related files One order record and two item records linked by order_id Preserves relationships, but requires managing multiple files

For product analysis, one row per item is a useful choice. Repeat the order identifier, customer details, and currency beside each item. That repetition lets each row stand on its own.

Watch for separate repeating groups. An order with two items and three payment records can turn into six rows if the conversion combines every item with every payment. Keep those groups in separate related files unless each combination has a real meaning.

Keep Missing Values Different From Real Values

The sample contains two different situations. Maya has an empty note element. Luis has no note element at all. Luis also has no email element. A basic CSV export may represent all three cases with blank cells.

That may be fine for a contact list. It may be wrong for an update file. An empty value might mean “clear the existing note,” while an absent element might mean “leave the existing note alone.” Conversion should follow the receiving system's rules.

If that distinction matters, add a presence column. A field named note_present could contain true for Maya and false for Luis. The separate note field can remain blank for both records.

CSV does not provide a universal missing-value marker. Text such as NULL or N/A has meaning only when the receiving application interprets it that way. Avoid replacing missing quantities with zero unless zero is actually correct. A missing quantity and a recorded quantity of zero describe different situations.

Run a Small Conversion Before Processing Everything

Build a sample that includes ordinary records and awkward ones. Include attributes, repeated items, missing fields, non-English characters, and a value containing a comma. A sample made only from simple records can hide the problems that appear later.

  1. Save the source. Keep an untouched copy of the XML and work from a duplicate.
  2. Confirm the row definition. Choose the repeating element that should produce each record.
  3. Map the fields. Include needed attributes and give repeated names distinct headers.
  4. Set repetition and blank-value rules. Record how multiple items and absent elements will appear.
  5. Convert the sample. Inspect its raw text and import it into the intended application.
  6. Process the full file. Apply the checked settings and reconcile the final counts.

For a non-sensitive sample, an XML to CSV converter can provide a starting output to inspect. Check its available mapping controls before relying on the result. A successful download does not prove that attributes, repeated records, or blank values were handled as you intended.

For the sample above, an item-based export could look like this:

order_id,currency,customer_name,customer_email,item_sku,item_name,quantity
00127,USD,Maya Chen,[email protected],P10,Notebook,2
00127,USD,Maya Chen,[email protected],P22,Pen,1
00128,USD,Luis Ortiz,,P10,Notebook,1

This output intentionally leaves out notes. If notes are needed, add their columns to the mapping. The blank email field still occupies its proper position, which keeps the item code under the correct header.

Check CSV Formatting and Spreadsheet Compatibility

A comma inside a value must not become an accidental column separator. Under the conventions described in CSV formatting rules, fields containing commas, double quotes, or line breaks belong inside double quotes. A double quote within a quoted field is written twice.

For example, the value Notebook, "Large" becomes "Notebook, ""Large""" in CSV. Use a CSV-aware exporter to handle this escaping. Splitting every line at each comma will break valid quoted fields. Counting physical lines can also give the wrong record count when cells contain line breaks.

Import the file through your spreadsheet's import controls. Select the delimiter and encoding explicitly. Commas and UTF-8 are common choices, but the receiving application may expect different settings.

Set identifiers to text during import. The order code 00127 can become 127 if the spreadsheet treats it as a number. Quoting that value in CSV does not reliably prevent automatic type conversion. Check long identifiers, date-like codes, decimal values, and accented names after import.

If exported text begins with a formula trigger, check how your spreadsheet handles it. Import untrusted text as text where supported. Any added escape characters should follow a documented policy, since changing a value can affect later imports.

Protect the Source and Reconcile the Result

Before uploading XML, check whether the service processes files locally or sends them to a server. Read its retention information. Customer details, internal identifiers, and credentials can appear in attributes as easily as in element text. Use an approved local workflow for sensitive files when external processing is unsuitable.

Finish with a focused output check:

  • Compare the expected record count with the parsed CSV row count.
  • Match several identifiers back to their source elements.
  • Confirm that attributes and optional fields appear in the intended columns.
  • Check repeated groups for lost entries or multiplied combinations.
  • Inspect blanks, quoted punctuation, character encoding, and leading zeros.
  • Reconcile meaningful totals, accounting for repeated parent values.

Keep the XML, CSV, and mapping notes together. A flat export generally cannot recreate the full original structure. It may omit relationships, formatting, comments, or details you chose not to export. Preserving the source gives you a reliable starting point when someone requests another field later.

Make Every Row Tell a Reliable Story

A usable CSV has a clear promise: each row represents the same kind of thing, and each column has a consistent meaning. Elements supply values. Attributes supply details that deserve deliberate attention. Repeated nodes determine the row structure. Missing values need rules that fit the destination.

Begin with a small sample and a written mapping. Check the result in the application that will actually use it. Those habits turn a file that merely opens into a table people can filter, calculate, and trust.

Try it yourself. Everything in this guide works with the free Delimiter Converter — no sign-up, and nothing you paste is stored. Browse all text tools or jump to counters and list clean-up.
Keep reading