Introduction to XML
XML (eXtensible Markup Language) is a flexible, self-describing markup language designed to store and transport structured data in a format that both humans and machines can read.
XML vs HTML
HTML uses a fixed, predefined set of tags to describe how content should be displayed. XML, by contrast, lets you invent your own tag names to describe what the data actually means — there's no fixed vocabulary, which is why XML is called 'extensible'.
XML doesn't do anything on its own; it purely carries structured data. What happens with that data — how it's displayed, validated, or transformed — is handled by other tools and technologies built around it.
A First XML Document
An XML document begins with a declaration specifying its version and encoding, followed by a single root element containing all the data.
<?xml version="1.0" encoding="UTF-8"?>
<student>
<name>Kagiso Mahlangu</name>
<age>22</age>
<course>Cloud Computing</course>
</student>
Common Mistakes
- Confusing XML's custom tags with HTML's fixed set of predefined tags — in XML, you invent the tag names yourself.
- Forgetting the XML declaration at the top of the document.
- Assuming XML automatically displays content in a browser the way HTML does — XML only describes data, without inherent visual styling.
- Omitting a single root element wrapping the entire document.
Professional Tip
Think of XML as a way to describe the meaning and structure of data, completely separate from how it might eventually be displayed or used — that separation is exactly what makes it 'extensible' to so many different use cases.
Your Turn
Write an XML document describing a book, with elements for title, author, and year, wrapped in a single root element called book.
Mini Quiz
What is the key difference between XML and HTML?