What Is XML?
XML is a text-based format for storing and exchanging structured information. It uses descriptive tags to show what each piece of data means and how different pieces of information relate to one another.
XML means Extensible Markup Language
XML stands for Extensible Markup Language.
It is a plain-text format designed to describe, organise, store and exchange structured information.
XML does this using tags that identify the meaning and structure of the data.
What does XML look like?
Imagine that we want to store information about a customer.
The information is surrounded by tags such as <name>, <email> and <orders>.
These tags give meaning to the values rather than simply storing them in a fixed position.
Opening and closing tags
Most XML elements have an opening tag and a closing tag.
Here:
<name>
This is the opening tag. It marks the beginning of the element.
</name>
This is the closing tag. The forward slash indicates the end of the element.
XML is hierarchical
One of XML's most important features is that elements can contain other elements.
This creates a tree-like hierarchy.
In this example, the shop contains a customer, the customer contains orders, and each order contains its own information.
An XML document needs a root element
A well-formed XML document has one outermost element that contains the rest of the document.
Here, <customers> is the root element.
XML elements can also have attributes
Attributes provide additional information about an element.
In this example:
These are attributes attached to the customer element.
Why is XML called "extensible"?
XML does not give you a fixed set of tags.
Instead, you can create tags appropriate to the information you are describing.
A different system might use:
The tags can therefore be designed around the type of information being stored.
The XML declaration
XML documents may begin with a declaration such as:
This tells software that the document uses XML version 1.0 and that the text is encoded using UTF-8.
Important: XML is a text format, so character encoding matters. UTF-8 is extremely common because it can represent characters from many languages and writing systems.
Some characters need special handling
Because characters such as angle brackets are used as part of XML syntax, certain characters must be represented using special entity references when they are intended as data.
| Character | XML representation |
|---|---|
| < | < |
| > | > |
| & | & |
| " | " |
| ' | ' |
XML has strict structural rules
XML must be well formed for an XML parser to process it correctly.
Tags must close
Elements normally need corresponding opening and closing tags.
Tags must nest correctly
Elements cannot overlap one another incorrectly.
One root element
The document must have one outermost root element.
XML is case-sensitive
<Name> and <name> are treated as different tags.
Correct nesting matters
This is valid:
But this structure is invalid:
The elements have been closed in the wrong order.
XML and HTML look similar, but they have different purposes
Both use angle-bracket tags, but they are designed for different jobs.
| XML | HTML |
|---|---|
| Describes and structures data | Structures content for web pages |
| Custom tags can be created | Uses predefined HTML elements |
| Focused on information | Focused on webpage structure and presentation |
| Strict syntax | Browsers are often more forgiving |
XML and JSON can represent similar information
XML and JSON are both commonly used to represent structured data.
For example, this XML:
could be represented in JSON as:
JSON is often more compact, while XML offers features such as attributes, namespaces and document-oriented structures that can be useful in more complex systems.
What is XML used for?
XML has been used extensively for exchanging and storing structured information across many kinds of software.
Website sitemaps commonly use XML
A website can provide an XML sitemap containing information about its pages.
Search engines and other software can process this structured information automatically.
Why XML matters in data management
XML allows information to describe its own structure.
Instead of relying purely on column positions or an external explanation, tags can identify what individual pieces of information represent.
This makes XML useful when information needs to move between systems while retaining a clear hierarchical structure.
XML is still plain text
Although XML can represent complex structures, the file itself is text.
This means an XML file can be opened in a text editor, inspected by a person and processed by software.
Text with structure and meaning.
XML is a text-based language for representing structured information. It uses tags, elements, attributes and hierarchical relationships to describe what data means and how different pieces of information fit together.