Affiliate
Never lose a file again. Back up everything you make here with pCloud, free to startSecure Swiss cloud storage for your files, on every deviceStart free with pCloud and upgrade only if you need more spaceOne click from download to safe backup. Try pCloud free

TXT to XML Converter Online

Convert plain text, TXT files, logs, key/value pairs, and delimited rows into clean XML. Choose the structure, customize XML tags, preview instantly, and download a valid .xml file. No upload or signup required.

TXT to XML Example

Plain Text Input
text
Alice Johnson
Mateo Rivera
Priya Shah
XML Output (Lines mode, Line numbers on)
xml
<?xml version="1.0" encoding="UTF-8"?>
<people>
  <person line="1">Alice Johnson</person>
  <person line="2">Mateo Rivera</person>
  <person line="3">Priya Shah</person>
</people>

How It Works

1

Paste or upload

Paste text or upload a .txt file.

2

Choose structure

Lines, paragraphs, key/value pairs or delimited rows. Set root and item tags in Options.

3

Copy or download

Copy the XML or download it as a .xml file.

TXT to XML in Python

If you need to automate text-to-XML conversion in a workflow, use a small script that escapes XML-sensitive characters and writes predictable tags. The online tool is faster for interactive cleanup; Python is better for scheduled or repeatable conversion jobs.

Pythontxt_to_xml.py
from xml.sax.saxutils import escape

lines = [
    "First support ticket",
    "Second support ticket",
    "Third support ticket",
]

xml = ['<?xml version="1.0" encoding="UTF-8"?>', "<tickets>"]
for index, line in enumerate(lines, start=1):
    xml.append(f'  <ticket line="{index}">{escape(line)}</ticket>')
xml.append("</tickets>")

with open("tickets.xml", "w", encoding="utf-8") as file:
    file.write("\n".join(xml))

Frequently Asked Questions

Complete TXT to XML Guide

How to Convert TXT to XML Online

A plain text file has content, but it usually does not have structure. XML adds that structure by wrapping the text in named elements. This makes the data easier to validate, import, transform, search, and share with systems that expect tagged records.

Choose the Right TXT to XML Mode

Use Lines when each line is a record, such as a list of names, SKUs, IDs, log entries, or short notes. Use Paragraphs when blank lines separate records, such as article snippets, descriptions, support replies, or scraped text blocks.

Use Key/value when your text is made of labelled values: name: Alice, price=19.99, or tab-separated label/value pairs. Each block of lines separated by a blank line becomes one record, and each label becomes a child element. Use Delimited rows for CSV-like or TSV-like text where each row contains multiple columns.

What Each Mode Produces

These examples use the default root tag records and item tag record.

Lines: one element per non-empty line.

Alice Johnson
Mateo Rivera

<records>
  <record>Alice Johnson</record>
  <record>Mateo Rivera</record>
</records>

Paragraphs: one element per blank-line separated block; line breaks inside a block are kept in the text.

First note.

Second note,
two lines long.

<records>
  <record>First note.</record>
  <record>Second note,
two lines long.</record>
</records>

Key/value: one record per block, one child element per label. Lines without a separator become value-1, value-2, and so on.

name: Alice
role: Engineer

name: Mateo
role: Analyst

<records>
  <record>
    <name>Alice</name>
    <role>Engineer</role>
  </record>
  <record>
    <name>Mateo</name>
    <role>Analyst</role>
  </record>
</records>

Delimited rows: one record per row; with First row headers on, the header cells become element names, otherwise columns are named field-1, field-2, and so on.

name,role
Alice,Engineer

<records>
  <record>
    <name>Alice</name>
    <role>Engineer</role>
  </record>
</records>

Turn on Line numbers to add a line attribute (source line number) in Lines mode, or an index attribute (record number) on records in the other modes.

TXT to XML Best Practices

  • Use short, readable XML tag names such as record, line, or item.
  • Prefer key/value mode when every line has a label and value, and separate records with a blank line.
  • Use CDATA when text contains markup snippets that should remain untouched.
  • Keep empty lines only when they carry meaning in the source text.
  • Download the result as .xml and validate it before importing into production systems.

When to Use XML Instead of Plain Text

XML is useful when systems need explicit field names, nested records, document interchange, or predictable parsing. Plain text is easier to read, but XML gives machines a reliable structure to work with. If your next step is spreadsheet analysis, try the JSON to Table converter after transforming data into a structured format, or skip XML entirely with TXT to CSV. Apps and APIs that expect JSON are better served by TXT to JSON, and several converted XML files can be combined into one document with the XML Merger.

Related Guides