How Do You Extract Tab-Separated Data from an XML File?

XML to TSV — Chunky Munster

To extract tab-separated data from XML, you flatten repeating XML records into rows and map the fields you care about into columns. If you want the fast path, try our free XML to TSV tool and skip the hand-parsing ritual.

The core trick is simple: XML is nested, TSV is flat. Each repeated item becomes one row, while its child elements or attributes become tab-separated columns. Once you know the repeating unit, the conversion stops being mysterious and starts looking like a normal data reshaping job.

What XML to TSV actually means

XML to TSV is not a format swap so much as a flattening step. You are deciding which node represents one record, then pulling values out of that node into a tab-delimited table.

That matters because XML can store structure that TSV cannot. A customer record might include nested addresses, multiple phone numbers, and metadata attributes. TSV can hold the final result cleanly, but you have to choose how to represent one-to-many data before you convert it.

In practical terms, this usually means:

If the XML is clean, this is mechanical. If it is messy, the hard part is not the tab-separated output; it is deciding what counts as one record and what should be left out.

Choose the repeating unit first

Before you convert anything, find the node that repeats. That node becomes the row boundary in your TSV file. Everything else is just a field.

For example, in an order feed, you might have one <order> per purchase and several nested fields inside it. If you flatten <line_item> values into columns, that works only if every order has the same number of line items. In most real feeds, that is false, so you either keep one row per order or split line items into a separate table.

A good rule: if a field can appear multiple times for one record, it usually should not become a single TSV column unless you join the values first. Otherwise your output turns into a half-broken spreadsheet with ambiguous data stuffed into one cell.

For related flattening work on text columns, see how tab-separated data gets turned into structured XML. The direction is reversed, but the mental model is the same: identify records, then map fields consistently.

Attributes, nested elements, and mixed content

XML gives you at least three ways to store data: elements, attributes, and mixed content. TSV does not care how elegant the source was. It only wants plain values separated by tabs.

Attributes are often useful for IDs, types, or flags. A node like <product sku="A12"> can become a row where sku is one column and the inner text or child nodes fill the rest. That is usually a clean fit.

Nested elements are more annoying. Suppose an address is stored as <address><city>...</city><zip>...</zip></address>. You flatten that by naming columns like address_city and address_zip. The prefix helps keep the output readable when multiple nested groups exist.

Mixed content is where XML likes to play tricks. If text and tags are interleaved inside one element, TSV conversion usually has to choose between preserving the text only, extracting selected child nodes, or discarding markup entirely. There is no universal right answer; there is only the version that matches the downstream use case.

When a browser tool is enough

For ad hoc exports, debugging, and one-off data cleanup, a browser-based converter is often the best tool. You paste the XML, map the fields, and get TSV without installing a parser or writing throwaway scripts.

That is especially useful when you need to inspect a vendor export, test an API response, or hand off data to someone who just wants a tab-delimited file. TSV is a boring format in the best sense: it opens in spreadsheets, text editors, and data pipelines without much drama.

If you already work with delimited text, the same habits apply here as they do in extracting or rearranging TSV columns. Once the data is flat, the rest is just column hygiene.

Use a tool when you need speed, not when you need a full ETL pipeline. If the XML arrives daily, is huge, or needs custom business rules, write the transformation in code. If you just need the data to stop being XML-shaped, a converter is enough.

Things that usually go wrong

Most bad XML to TSV conversions fail in predictable ways. The first failure is choosing the wrong record node. The second is flattening repeated fields into one column and silently losing structure.

Another common issue is inconsistent XML. One record has <price>, another has <amount>, and a third has both. A converter cannot guess your schema, so you either normalize those names first or accept that some rows will have blank cells.

Watch out for whitespace too. XML often includes indentation and line breaks that are useful for humans but irrelevant to TSV. If you need to clean noisy text before or after export, a related utility like the text cleaner can help remove stray characters and normalize input.

There is also the encoding problem. If your XML contains smart quotes, special symbols, or non-ASCII text, the TSV output should preserve them as UTF-8 unless the downstream system demands something else. If values look mangled, check encoding before blaming the conversion.

How to think about schema mapping

A useful way to plan the transformation is to sketch the output table first. Write the column names you want, then work backward to the XML paths that supply those values. That keeps you from overfitting the source structure.

For a product feed, you might end up with columns like id, name, price, and category. If the source XML stores category as <taxonomy><label>, you do not need to mirror that shape in TSV. You only need a stable, useful field.

In code, the mapping idea looks like this:

record = /catalog/product
columns = {
  id: @sku,
  name: title,
  price: pricing/amount,
  category: taxonomy/label
}

That is not a real language syntax, just the logic in miniature. Find the record, point each column at a path, then repeat for every product. The converter does the same thing under the hood.

Real-World Example

Here is a small XML sample and the TSV you would expect after flattening it.

<catalog>
  <product sku="A12">
    <name>Widget</name>
    <price>19.99</price>
    <stock>42</stock>
  </product>
  <product sku="B77">
    <name>Gadget</name>
    <price>29.50</price>
    <stock>8</stock>
  </product>
</catalog>

After XML to TSV conversion, the output becomes:

sku	name	price	stock
A12	Widget	19.99	42
B77	Gadget	29.50	8

If you had a nested address object inside each product, you would flatten it into separate columns instead of trying to embed XML inside TSV. For example, <address><city>Paris</city><zip>75001</zip></address> would usually become address_city and address_zip.

And if a field repeats, such as multiple tags or phone numbers, you have to choose a strategy. You can join values with a comma, create extra columns, or split the repeated data into its own TSV file. TSV does not solve that problem for you; it only makes it obvious.

Frequently Asked Questions

How do I convert XML to TSV without coding?

Use a browser converter that lets you paste XML and export TSV directly. This is the easiest option for one-off files, API responses, and debugging messy exports. If your XML has a clear repeating record, the conversion is usually straightforward.

Can XML attributes become TSV columns?

Yes. Attributes like id, type, or sku are often ideal TSV columns because they are already scalar values. The main thing is to map them consistently so every row has the same structure.

What if my XML has nested arrays or repeated child nodes?

That is where flattening gets tricky. You can join repeated values into one cell, split them into separate tables, or choose one repeated node as the record boundary and ignore the rest. The right answer depends on whether you need a simple export or a relational-style reshape.

Is TSV better than CSV for XML exports?

TSV can be nicer when your data contains commas, quotes, or prose-like text, because tabs are less likely to appear inside values. CSV is more common, but TSV is often easier for clean machine-to-machine transfer. If the downstream system accepts TSV, it is a solid choice.

The Bottom Line

Converting XML to TSV is mostly about flattening structure without losing meaning. Once you identify the repeating record, choose your columns, and decide what to do with nested or repeated data, the rest becomes a simple export.

For small jobs, a browser tool is the least painful route. For larger pipelines, the same logic still applies, but you will probably encode it in code instead of clicking through a converter.

If you have a file sitting in front of you right now, give the XML to TSV tool a spin and see how quickly the shape falls into place.

// try the tool
try our free XML to TSV tool →
// related reading
← all posts