XML to Markdown: Tags Out, Hierarchy In
XML has a habit no other format shares: it writes the name of every element twice. Once to open it, once to close it. Add namespace prefixes, add attributes, add the indentation that makes it legible, and you routinely end up with a file where the tags outweigh the content they wrap. A product catalogue with 200 items can run to thousands of lines and still contain about a page and a half of actual information.
Converting XML to Markdown keeps the tree and drops the ceremony. Element nesting
becomes heading levels, repeating siblings become lists or tables, and the angle brackets go away.
Upload a .xml file above and you'll get it back in a few seconds — free, no sign-up,
50 MB ceiling, nothing retained.
What the Element Tree Turns Into
The conversion walks the document and translates each construct:
- Container elements become headings. An element with child elements but no text of its own is a section. Its depth in the tree sets the heading level, so a five-deep enterprise schema arrives as a properly outlined document.
- Leaf elements become labelled values.
<author>Ursula Le Guin</author>reads as author: Ursula Le Guin. One name instead of two, no brackets. - Repeating siblings become lists or tables — covered below, because it's where most of the value is.
- Mixed content is preserved inline. This is the case where text and child
elements interleave, as in
<para>See the <ref>appendix</ref> for details</para>. Naive converters split that into fragments and you lose the sentence. It should come through as one readable line with the reference intact. - Comments, processing instructions and the XML declaration go. None of them are content.
Attributes: The Part People Lose Without Noticing
XML stores data in two places — between the tags, and inside them. Element text is obvious.
Attributes are easy to overlook, and a lot of naive extraction quietly drops them. That's fine
when they're metadata like id="4471". It's a disaster when they're the payload.
Which is common. <price currency="GBP">49.99</price> is meaningless without
the currency. Configuration formats are worse — Maven, Ant, Spring, Android manifests and .NET
app.config files often put almost everything in attributes, so an element-text-only
extraction of one of those returns a document that's structurally correct and almost entirely
empty. If you convert a config file and the output looks suspiciously short, this is why.
In Markdown output, attributes should sit alongside the element they belong to rather than vanish — rendered as a short qualifier next to the value, or as extra columns when the element is part of a repeating set. Check the first screen of output against the source before you trust it with anything important. Ten seconds of skimming beats a confused conversation with a model later.
Repeating Siblings Become Tables
XML's best-case shape is a parent holding many identical children: <item>
elements in an RSS feed, <row> elements in a database export,
<employee> records in an HR dump. Every child has the same sub-elements in the
same order.
That collapses into a single Markdown pipe table. Sub-element names become column headers, each record becomes a row, and the tag repetition — which in the raw file meant writing every field name twice per record — happens exactly once, in the header. It's the largest single reduction you'll see from any XML conversion, and it's the reason to pick Markdown over flat text for anything record-shaped.
It degrades when records are ragged — optional elements present on some children and not others, or one child containing a nested block the others don't have. You'll get gaps, or the nested part pushed out below the table. If your data is genuinely rectangular, exporting to CSV and using the CSV to Markdown converter produces cleaner tables. And if the source is JSON-shaped rather than tag-shaped, the JSON to Markdown converter handles the same problem from the other direction.
Namespaces, Envelopes and Enterprise Noise
Real-world XML is rarely clean. Three things bloat it beyond its information content:
- Namespaces.
xmlnsdeclarations and prefixes likesoap:,xsi:,atom:ordc:exist to prevent name collisions between vocabularies. They mean nothing to a reader. Prefixes get stripped in conversion so<dc:creator>reads as creator. The one time to care is when two namespaces genuinely use the same local name for different things — rare, but check if you're merging vocabularies. - SOAP envelopes. A web service response wraps the part you want in
EnvelopeandBody, frequently plus headers full of security tokens and routing data. Converting gives you a document where the payload is finally visible instead of buried four levels down inside boilerplate you have to mentally skip. - Schema references.
xsi:schemaLocation, DTD declarations and validation attributes describe how the file should be checked, not what it says. Noise for every purpose here.
RSS and Atom feeds sit at the friendly end of this. They're uniform, shallow, and convert to a clean list of dated entries — a reasonable way to hand a model a month of posts from a blog. Note that feed descriptions usually contain HTML escaped inside the XML, which arrives as markup in your output; run that through the HTML to Markdown converter if you want it clean, or use Web2Txt to fetch the pages properly.
When You Should Keep the Raw XML
Straight answer, since plenty of pages selling converters won't give you one: models read XML fine. It's verbose, but it's unambiguous and extremely well represented in training data. Converting is a choice, not a requirement.
Keep it raw when you're asking for XPath expressions, an XSLT stylesheet, a parser, or a schema — anything where the model must reproduce exact element names, namespace prefixes and the attribute-versus-element distinction. Markdown deliberately smooths over precisely those details. Paste a representative fragment of the real file instead.
Convert when a person needs to read it, when you're trying to understand an unfamiliar schema quickly, or when the raw file is mostly tags and you're short on context. Those are real wins. Anything else is preference.
The XML You Didn't Know Was XML
A fair number of formats you think of as binary are zipped XML underneath. Rename a
.docx to .zip, unpack it, and you'll find document.xml plus a
pile of relationship files. EPUB is the same story: XHTML content documents and an XML package
manifest in a zip. So is .pptx, and so is .xlsx.
You could unzip one and convert the XML by hand. Don't — the internal markup is full of styling runs, revision tracking and layout instructions that swamp the text. Use Word to Markdown or EPUB to Markdown, which know which parts of that XML are content and which are formatting instructions. This page is for XML you were handed as XML: feeds, exports, API responses, config, data interchange.
Frequently Asked Questions
How do I convert XML to Markdown?
Upload the .xml above and the document structure maps onto Markdown — element hierarchy becomes heading levels, repeated sibling elements become lists or tables. Free, 50 MB per file, no sign-up. It keeps the shape of the document, which is the difference from flattening it to text.
Does the element hierarchy become heading levels?
That is the mapping, yes — a nested element becomes a deeper heading. It works well for document-shaped XML like DocBook, TEI or an article export, where the nesting genuinely reflects sections within sections. It works poorly for data-shaped XML where nesting reflects a database schema, and you get twelve heading levels describing a record.
What happens to namespace prefixes?
They are dropped from the output. A heading reading dc:title or tei:head tells a human nothing and tells a model less, so prefixes are stripped and the local element name is used. If two namespaces in the same document define the same local name, they will collapse together — rare, but worth a look if headings seem duplicated.
Is this useful for converting DocBook or DITA?
For a first pass, yes. Prose, sections, lists and inline emphasis carry over well because those formats mark them explicitly. Conditional profiling, content references, entity includes and cross-reference resolution do not survive — those are the parts that made the format worth using, and no generic converter can resolve them.
Which should I pick for a large XML corpus?
Text, in most cases. If you are building embeddings across thousands of records, heading syntax is overhead repeated on every chunk with no retrieval benefit. Markdown earns its place when a human or a model is going to read one document and needs to know where the sections are.
Plain Text Instead, and the Rest of the Suite
If you want no structure at all — text for embeddings, a search index, or the lowest possible token count — use XML to plain text, which pulls the content out from between the tags and leaves nothing else behind. The format toggle at the top of this page switches between the two and keeps your file loaded, so comparing both outputs takes one click. The token counter under the output tells you what each one costs.
If the XML is one file in a project — a config, a build descriptor, a fixture — converting it alone gives a model the data without the code around it. The GitHub repository to text converter and the local directory converter let you take the XML and its consumers together, which is usually the more useful unit. File2Txt handles every supported format in one place, and the guide to preparing files for LLMs covers the general principles.
Repo2Txt is built and maintained by v12hero, an independent developer building privacy-first native and web apps.