## What is XML?
XML is a markup language for storing and transporting structured data. It uses tags (like HTML) to define elements and organize information in a hierarchical, human-readable format.
Think of XML as a way to label and package data so both humans and computers can understand it.
## What XML Looks Like
```xml
<book>
<title>The Great Gatsby</title>
<author>F. Scott Fitzgerald</author>
<year>1925</year>
<genre>Fiction</genre>
</book>
```
The tags describe what each piece of data represents. Any program can read this and know exactly what each field means.
## Why XML Exists
Before XML, different systems stored data in incompatible formats. XML provided a universal standard for data exchange between different platforms, languages, and systems.
If one system uses Java and another uses Python, both can read and write XML. It bridges the gap.
## Where XML is Used
**Configuration Files**: Many applications store settings in XML. Android apps use XML for layouts and configurations.
**Data Exchange**: APIs used to return XML (now JSON is more common, but XML still exists in legacy systems).
**Document Formats**: Microsoft Office files (.docx, .xlsx) are actually ZIP files containing XML documents.
**Web Services**: SOAP APIs communicate using XML messages.
**RSS Feeds**: News and blog feeds use XML to distribute content.
## XML vs JSON
**XML**: More verbose, uses tags, supports attributes, better for complex documents.
```xml
<person>
<name>John</name>
<age>30</age>
</person>
```
**JSON**: Cleaner syntax, less verbose, easier to read, dominant in modern web development.
```
{
"name": "John",
"age": 30
}
```
JSON has largely replaced XML for APIs, but XML remains important in many domains.
## Key Features
**Self-Descriptive**: Tags explain what the data means, not just what it is.
**Hierarchical**: Data organizes into parent-child relationships naturally.
**Extensible**: You define your own tags based on your needs.
**Platform-Independent**: Works across all programming languages and systems.
## Common XML Technologies
**XPath**: Query language for selecting parts of XML documents.
**XSLT**: Transform XML into other formats (HTML, PDF, different XML).
**XML Schema**: Define rules for what valid XML should look like.
**DOM Parser**: Read entire XML file into memory for manipulation.
**SAX Parser**: Read XML sequentially without loading everything into memory.
## When to Use XML
**Use XML when**:
- Working with legacy systems that require it
- Need to store complex, hierarchical documents
- Configuration files need human readability
- Industry standards require it (finance, healthcare)
**Use JSON when**:
- Building modern web APIs
- Need lightweight data transfer
- JavaScript is involved (JSON is native to JavaScript)
## The Bottom Line
XML is not trendy anymore, but it is not going away. Enterprise systems, legacy APIs, and document formats still rely heavily on XML. Every developer should understand XML basics because you will encounter it eventually.
Modern projects favor JSON, but XML literacy remains valuable for working with existing systems and understanding how data exchange evolved.