XML (eXtensible Markup Language) predates JSON and, despite JSON winning the API world, it’s far from dead: SVG, RSS/Atom feeds, Office documents (.docx), Android layouts, Maven pom.xml and SOAP are all XML. Knowing how to read and tidy it is still a useful skill.
How XML is structured
XML describes data with nested elements wrapped in tags, which can carry attributes:
<book id="42" lang="en">
<title>The Hobbit</title>
<author>Tolkien</author>
</book>
Every opening tag needs a matching closing tag (or be self-closing, <br/>), tags must nest properly, and attribute values must be quoted. Get any of that wrong and the document won’t parse.
Well-formed vs valid — an important distinction
These sound the same but aren’t:
- Well-formed means the XML follows the syntax rules above — correct tags, nesting and quoting. Any XML parser can check this.
- Valid means it also matches a specific schema (a DTD or XSD) that defines which elements and attributes are allowed. That needs the schema.
Most online tools — including ours — check that XML is well-formed. That catches the everyday errors (an unclosed tag, a stray &), which is what breaks parsing in practice.
XML vs JSON: when to use which
- JSON is lighter and the default for web APIs and configs that a program reads.
- XML shines where you need attributes, mixed content (text and elements together), namespaces, comments, or where an ecosystem already standardized on it (SVG, RSS, office formats).
They’re not competitors so much as tools for different jobs.
XML, JSON and HTML side by side
| Aspect | XML | JSON | HTML |
|---|---|---|---|
| Purpose | Store/transport data | Store/transport data | Display documents |
| Tags | Custom, any name | No tags (braces) | Fixed set (<p>, <div>) |
| Attributes | Yes | No (keys only) | Yes |
| Strictness | Must be well-formed | Strict | Lenient, browsers forgive errors |
| Comments | <!-- --> | None | <!-- --> |
XML and HTML look alike because both descend from SGML, but XML lets you invent your own tags and enforces strict syntax; HTML has a fixed vocabulary and browsers tolerate sloppy markup. XHTML was the attempt to make HTML obey XML’s rules.
A real-world example: RSS
An RSS feed is just XML with agreed-upon tag names:
<rss version="2.0">
<channel>
<title>My Blog</title>
<item>
<title>First post</title>
<link>https://example.com/first</link>
</item>
</channel>
</rss>
SVG images work the same way — an <svg> document is XML you can open in a text editor and edit by hand.
Common gotchas
- Escape the special characters. Five characters need entities in text:
<(<),>(>),&(&),"(") and'('). A raw&is the single most common cause of a broken feed. - XML is case-sensitive.
<Title>and<title>are different elements, and a closing tag must match exactly. - One root element only. A well-formed document has exactly one top-level element wrapping everything else.
Because SVG is XML, the same tidy-up applies when you edit vector images — see our guide on PNG to SVG.
Format and validate it in your browser
The XML formatter beautifies messy XML into a readable indented structure, minifies it back to one line, and flags syntax errors — all locally, so even sensitive config never leaves your device.
Related tools
- Working with JSON instead? Use the JSON formatter.
- Converting between JSON and YAML? Try JSON ⇄ YAML.