What the XML to text converter produces
Sometimes you do not need another data format, just something a person can read. This XML to text converter removes the angle brackets and closing tags and writes the content as simple key: value lines, with indentation for nested elements. It is useful for pasting an API response into a support ticket, reading a configuration over a chat message, or giving a non-technical colleague a quick look at an export.
Example: a list of records
<catalog>
<book id="bk101" lang="en">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<price>44.95</price>
</book>
<book id="bk102" lang="en">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<price>5.95</price>
</book>
</catalog>
#1
@id: bk101
@lang: en
author: Gambardella, Matthew
title: XML Developer's Guide
price: 44.95
#2
@id: bk102
@lang: en
author: Ralls, Kim
title: Midnight Rain
price: 5.95
Top-level records are numbered and separated by a blank line. The <catalog> wrapper is skipped because it only holds the list.
Example: nested data without attribute markers
With the Attribute prefix field cleared:
<profile id="7">
<name>Ava</name>
<address><city>Denver</city><zip>80202</zip></address>
<tags><tag>admin</tag><tag>beta</tag></tags>
</profile>
name: Ava
address:
city: Denver
zip: 80202
tags:
tag: admin, beta
id: 7
Nested elements are indented under their parent, and repeated simple values are joined with commas on one line. Without a prefix, attributes are listed after the child elements.
When plain text is the right choice
Plain text survives every channel: it pastes cleanly into chat apps, issue trackers, emails and terminal notes without any rendering, and screen readers handle it well. It also hides the parts of XML that distract non-technical readers, such as namespaces, closing tags and entity escapes, while keeping every value visible. For a quick sanity check of an export, reading the text version is often faster than scanning the raw XML.
Good to know
- This is a readable summary, not a reversible format. Use XML to JSON or XML to YAML if the result must be parsed again.
- Comments and the XML declaration are omitted; CDATA content appears as plain text.
- For HTML pages rather than XML data, the HTML to text tool is the better fit.
Tips for long exports
- Trim first. For a ticket or an email, a handful of records is usually enough. Cut the XML down to the records that matter, keeping the wrapper element, and convert only those.
- Keep the prefix when names clash. In
<item id="1"><id>A7</id></item>an attribute and a child element share a name. With the default@prefix they appear as@id: 1andid: A7; without it, both lines readid. - Attach rather than paste. Some chat and ticket systems trim leading spaces, which flattens the indentation. Use Download and attach the .txt file when the nesting matters.
Privacy
The text is produced in your browser and the XML is not uploaded, except when you choose Load URL or Save & Share.
Convert XML to text in Python
To get the plain text out of XML, parse it with xml.etree.ElementTree and call itertext(), which walks every text node in document order. The mistake to avoid is reading element.text: it only holds the text before the first child element, so for an element that contains other elements it is None or a fragment. Entities such as & are decoded for you, and " ".join(text.split()) collapses the whitespace left over from indentation.
import xml.etree.ElementTree as ET
data = """<note id="7">
<to>Ann</to>
<body><p>Meet at noon.</p><p>Bring tea & cake.</p></body>
</note>"""
root = ET.fromstring(data)
body = root.find("body")
print(repr(body.text)) # None: .text stops at the first child
print(" ".join(body.itertext())) # every text node below <body>
# the whole document, with runs of whitespace collapsed
print(" ".join(" ".join(root.itertext()).split()))
For a labelled key: value view of the same document, paste it into the converter above.