RUNWEBTOOLS
English
Data Formats & Encoding

What Is XML? Tags, Attributes, and How It Works

Updated 2026-07-06

XML predates JSON as the web's data format and still runs quietly underneath a huge amount of software — office documents, RSS feeds, SVG images, sitemaps, and countless enterprise systems. If tags and angle brackets look intimidating, this guide breaks XML down into the handful of rules that actually matter.

What XML is

XML (eXtensible Markup Language) is a text format for storing structured data using tags. Unlike HTML, it has no predefined tags — you invent element names that describe your own data, which is what “extensible” means.

<book id="42">
  <title>The Pragmatic Programmer</title>
  <author>Hunt</author>
  <price currency="USD">39.99</price>
</book>

The building blocks

  • Elements — an opening tag, content, and a matching closing tag: <title>…</title>.
  • Attributes — name/value pairs on the opening tag, in quotes: id="42".
  • Nesting — elements contain other elements, forming a tree with a single root element at the top.
  • Empty elements — can self-close: <br />.

Well-formed XML

XML has strict rules; break them and a parser rejects the whole document. To be “well-formed”:

  • Every opening tag has a matching closing tag.
  • Tags are properly nested (no overlapping).
  • There is exactly one root element.
  • Attribute values are always quoted.
  • The five special characters are escaped (see below).

Escaping special characters

Because < and & have structural meaning, literal ones must be written as entities: &lt;, &gt;, &amp;, &quot;, and &apos; — the same idea as HTML entities.

XML vs. HTML vs. JSON

  • vs. HTML: HTML has a fixed set of tags for displaying web pages; XML lets you define your own tags to describe data. HTML is also more forgiving, while XML is strict.
  • vs. JSON: JSON is lighter and now dominates web APIs. XML is more verbose but supports attributes, comments, namespaces, and schema validation, which is why it persists in documents and enterprise systems.

To tidy up a dense XML file and check it's well-formed, run it through the XML formatter. Working with HTML instead? The HTML formatter does the same for markup.

More in Data Formats & Encoding

See all Data Formats & Encoding guides →

Tools mentioned in this guide