XML
XML
An extensible markup language that expresses structure with tags
Introduction
XML (eXtensible Markup Language) is a markup language that expresses hierarchical structure by wrapping data in opening and closing tags. Because you can attach attributes to elements and strictly validate structure with a schema, it has long been used in documents and enterprise systems.
It is verbose but highly expressive, with a rich ecosystem including namespaces, schemas (XSD), and transformations (XSLT).
Syntax Features
- Every element consists of a pair of opening and closing tags.
- You can attach attributes to elements.
- Characters such as &, <, and > are escaped as entities.
- There must be a single root element that wraps everything.
Pros
- Can be strictly validated with a schema
- Highly expressive with attributes, namespaces, and more
- A mature document ecosystem
Cons
- Verbose due to repeated tags
- Relatively heavy to parse
- Losing ground to JSON in modern web APIs
Common Uses
- Document formats (Office, RSS)
- Enterprise and legacy integration (SOAP)
- Configuration and data exchange
Example
<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row>
<id>1</id>
<name>Ada</name>
<role>admin</role>
</row>
<row>
<id>2</id>
<name>Linus</name>
<role>editor</role>
</row>
</rows>