Learn XML

XML is a markup language built to store and transport data in a form that both people and programs can read, independent of any single application or vendor.

What Is XML?

XML stands for eXtensible Markup Language. Unlike HTML, which comes with a fixed set of tags for laying out a page, XML has no predefined tags at all — you invent the tag names that fit your own data. Because of this, XML is often described as a meta-language: a language for creating other markup languages and data formats.

Data vs. Display

HTML was designed to display data. A browser knows what a <table> or an <h1> tag should look like because those tags are built into the HTML specification. XML was designed to carry and describe data, and it says nothing about how that data should appear. The same XML file can be turned into a web page, loaded into a spreadsheet, sent to a mobile app, or read by another server — the data stays the same while the presentation changes around it.

A Simple XML Note

<!DOCTYPE html>
<html>
<body>

<pre>
&lt;note&gt;
  &lt;to&gt;Tove&lt;/to&gt;
  &lt;from&gt;Jani&lt;/from&gt;
  &lt;heading&gt;Reminder&lt;/heading&gt;
  &lt;body&gt;Don't forget me this weekend!&lt;/body&gt;
&lt;/note&gt;
</pre>

</body>
</html>

None of the tags in that example — <note>, <to>, <from>, <heading>, <body> — belong to any official standard. The author of the document chose them because they clearly describe the data inside.

XML Is Self-Describing

A well-written XML document carries its own meaning in its structure and tag names. Anyone reading the note above can guess that it's a reminder from Jani to Tove without consulting any documentation. This self-describing quality is what lets unfamiliar programs, and unfamiliar people, make sense of XML data on sight.

  • XML has no fixed set of tags — you design the vocabulary for your own data.
  • XML is both human-readable and machine-parseable.
  • XML is platform- and language-independent, so it can move data between systems that otherwise don't agree on anything.
  • XML keeps data separate from presentation, so one document can drive many different displays.
  • XML is extensible — new elements can be added later without breaking software that already reads the older ones.

A Self-Describing Plant Record

<!DOCTYPE html>
<html>
<body>

<pre>
&lt;plant&gt;
  &lt;common&gt;Bloodroot&lt;/common&gt;
  &lt;botanical&gt;Sanguinaria canadensis&lt;/botanical&gt;
  &lt;zone&gt;4&lt;/zone&gt;
  &lt;light&gt;Mostly Shady&lt;/light&gt;
&lt;/plant&gt;
</pre>

</body>
</html>
Note: XML doesn't do anything on its own. It's simply information wrapped in tags — a separate program still has to be written to store, transmit, or display that information.

Where XML Shows Up

XML is more common than it looks. It underlies configuration files for many applications, data feeds such as RSS and Atom, office file formats like .docx and .xlsx internally, SOAP-based web services, and everyday data exchange between servers that were never designed to talk to each other directly.

XML Used as a Data Feed

<!DOCTYPE html>
<html>
<body>

<pre>
&lt;feed&gt;
  &lt;item&gt;
    &lt;title&gt;New Article Published&lt;/title&gt;
    &lt;link&gt;https://example.com/articles/42&lt;/link&gt;
  &lt;/item&gt;
&lt;/feed&gt;
</pre>

</body>
</html>
AspectHTMLXML
Main purposeDisplays dataDescribes and carries data
Tag setFixed, predefined by the specOpen — defined by the author
Case sensitivityNot case sensitiveCase sensitive
Closing tagsSometimes optionalAlways required
Note: XML is not a replacement for HTML, and it was never meant to compete with it. HTML still shows information in a browser; XML still just describes and moves the underlying data. Most real systems use both together.

Exercise: XML Introduction

What is the primary purpose of XML?

Frequently Asked Questions

Is XML still used?
Yes, though less for web APIs, where JSON took over. It remains standard in publishing, finance, healthcare and configuration formats, and in document formats such as Office files and SVG, which are XML underneath.
What is the difference between XML and HTML?
HTML has a fixed set of tags and browsers forgive malformed markup. XML lets you define your own tags and enforces strict rules: every element must close and nest correctly. HTML describes a page; XML describes data.
What are XML namespaces for?
Preventing name collisions when documents combine vocabularies. If two schemas both define a title element, a namespace prefix makes clear which one is meant, so the same document can carry both without ambiguity.