XML Explained: The Strict Format for Sharing Data

XML explained in plain terms means a strict, self-describing format for storing and moving structured information between systems. The central question is how two organisations with completely different software can exchange data and both understand it, and the answer is that XML wraps every piece of data in named tags, so the meaning travels with the data itself.

XML stands for Extensible Markup Language. It was created in the late 1990s as a simpler cousin of SGML, the older standard used for large publishing projects, and it quickly became the default way for systems to exchange documents, from invoices and weather reports to office files and web feeds.

It is less fashionable today than it was, because JSON is lighter and easier for web apps, but XML still runs much of the world’s serious data exchange. This article explains what XML is, how it works, and how it compares with other formats.

Key takeaways

  • XML wraps data in named tags, so the meaning of each value travels with it.
  • It is strict: a document must be well formed, with every tag closed.
  • Schemas and DTDs define which tags are allowed and what they may contain.
  • XML suits documents, contracts, and regulated data that must be validated.
  • JSON is lighter for web apps, but XML still dominates formal data exchange.

What XML is

XML is a markup language for describing structured data. A markup language adds labels, called tags, around pieces of text to say what each piece is. An XML document might label a name, a price, and a date, so any program reading it can find each value without guessing.

The tags are not fixed. Unlike HTML, which has a set list of tags for headings and paragraphs, XML lets the author invent tags that fit the data. A bookshop can use tags for title, author, and price, while a weather service uses tags for temperature, wind, and rainfall. That extensibility is where the X in XML comes from.

XML is strict about its rules. Every opening tag needs a matching closing tag, tags must nest properly, and attribute values must be quoted. A document that breaks these rules is not XML at all, and a parser will refuse it rather than guess what was meant. That strictness is a feature: it makes errors visible instead of letting them slip through silently.

How XML works

An XML document is a tree. It starts with a single root element that contains all the others, and each element can contain text, attributes, or more elements nested inside it. A parser reads the document from top to bottom and builds that tree in memory, so a program can walk through it and pick out any piece it needs.

Attributes add extra information to an element without making it a child. A book element might carry an attribute for its language or its edition, while its child elements hold the title and the author. The distinction is a matter of style, and different designers draw the line differently.

Namespaces keep tags from different vocabularies apart. If two systems both use a tag called title, one meaning a book title and the other a person’s job title, a namespace prefix tells the parser which one is meant. Namespaces look like small web addresses attached to tag names, and they are essential when documents combine data from several sources.

Validation is where XML shows its strength. A schema, written in XSD or in the older DTD form, states exactly which elements may appear, in what order, and with what kind of content. A program can check a document against its schema before using it, and reject anything that does not match. Our guide to JSON explains the lighter format that has taken over much web work, and our guide to HTML explains the markup language that describes web pages rather than data.

A laptop on a dark desk with its screen showing glowing green nested tags in a document editor
A laptop screen shows glowing green nested tags in a document editor, the tree structure of an XML document: each piece of data labelled so any system can read it.

Comparing XML with other data formats

XML is one of several formats for structured data. JSON is its main rival for web work, HTML describes pages rather than data, and CSV handles simple tables. Each format suits a different kind of job.

The table below sets out the main contrasts.

Aspect XML JSON HTML
Built for Structured documents and data Data for web apps Web pages for people
Tags Any tags the author invents No tags, keys and values A fixed set of page tags
Strictness Very strict, must be well formed Strict but simpler rules Forgiving, browsers guess
Validation Schemas and DTDs built in Needs a separate schema tool Not designed for validation
Best for Contracts, feeds, office files APIs and web apps Pages people read

The practical result is that XML wins when data must be checked against a formal contract, JSON wins when a web app needs light, simple data, and HTML wins when the goal is a page for a person to read.

Where XML is used

Office documents are the most widespread use of XML. Modern Word, Excel, and PowerPoint files are zip archives that contain XML documents, and that is why a document can be opened by other programs, converted, and searched. The same is true of the OpenDocument format used by free office suites.

Web feeds are another major use. RSS and Atom feeds, which let readers follow blogs and news sites, are XML documents, and podcast feeds are XML too, carrying episode titles, descriptions, and audio file addresses in a standard shape that any app can read.

Business data exchange relies on XML heavily. Invoices, orders, and shipping notices travel between companies as XML documents in formats such as UBL and EDIFACT’s XML forms, and banks and governments use XML for filings and reports that must be checked against a strict schema.

Configuration files are a quieter use. Many programs store their settings as XML, because the format is readable by people and easy for a program to parse, and a misplaced setting is easy to find in a labelled document.

Publishing and archiving use XML for long-lived documents. Standards such as DocBook and TEI describe books and scholarly texts in XML, so a document can be converted to print, web, and ebook forms from a single source, and still be readable decades later.

Strengths and limits

The greatest strength of XML is its rigour. A document can be validated against a schema before anyone relies on it, and that check catches errors at the border between systems, where they are cheapest to fix. For regulated industries and formal contracts, that rigour is worth the extra weight.

It is also a strength that XML is self-describing. A person opening an XML file can usually work out what the data means from the tag names alone, without needing the program that created it. That readability matters for archives and for data that must outlive the systems that produced it.

The limits are real, though. XML is verbose: tags repeat for every value, so a document is much larger than the same data in JSON, and parsing it takes more work. For a web app that exchanges small messages quickly, that overhead is hard to justify, which is why JSON has taken over most new web APIs.

XML checklist

  • Close every tag and nest elements properly, or the document is not XML.
  • Quote every attribute value, even when it looks like a plain number.
  • Declare the encoding at the top so readers never have to guess.
  • Use a schema to validate documents before trusting them.
  • Use namespaces when a document mixes tags from different vocabularies.
  • Keep tag names clear and consistent across the whole document.
  • Escape special characters such as less-than signs in text content.
  • Prefer elements for data and attributes for metadata about that data.
  • Test with a real parser instead of reading the file by eye alone.

Frequently asked questions

What does XML stand for?

XML stands for Extensible Markup Language. Extensible means authors can invent their own tags, markup means the tags label the data, and language means it follows a defined set of rules.

Is XML the same as HTML?

No. HTML has a fixed set of tags for building web pages, while XML lets authors invent tags for any kind of data. HTML is forgiving of errors, while XML is strict and refuses malformed documents.

Is XML still used today?

Yes, widely. Office files, RSS feeds, podcast feeds, business invoices, and government filings all use XML, even though JSON has taken over much new web API work.

What is the difference between XML and JSON?

XML uses tags and is strict, with built-in validation through schemas. JSON uses keys and values, is lighter and simpler, and suits web apps that exchange small messages quickly. XML suits formal documents, JSON suits web APIs.

What is an XML schema?

A schema is a document that defines which elements and attributes another XML document may contain, in what order, and with what kind of content. A program can check a document against its schema and reject anything that does not match.

Can I open an XML file in a browser?

Yes. Most browsers display an XML file as a collapsible tree, which is a useful way to inspect its structure. For editing, a text editor or a dedicated XML editor is a better choice.

The bottom line

XML explained in one line is this: a strict, self-describing format that wraps data in named tags so different systems can exchange it, check it, and understand it.

It is heavier than its rivals and less fashionable than it was, but for documents, contracts, and regulated data, its rigour is still unmatched. Learn its rules, validate against a schema, and XML will carry your data faithfully for decades.

This article is general information about how XML works, not advice about choosing a data format for a particular project.

Latest articles

Scroll to Top