What is XML? The Document Markup Language
Before JSON took over the web, XML was the king of data exchange. It remains a critical standard for enterprise systems, document formats (like SVG and DocBook), and configuration.
Introduction
XML stands for Extensible Markup Language. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable.
Unlike HTML, which has predefined tags (like `<h1>`, `<p>`), XML allows you to define your own tags. It serves as a meta-language for defining other languages (like RSS, SVG, and SOAP).
Key Features
- Self-Descriptive: Tags describe the data they hold (e.g., `<price>10.99</price>`).
- Hierarchical: Data is structured as a tree of elements.
- Schema Support: XSD (XML Schema Definition) allows strict validation of data structure and types.
XML Syntax
XML looks similar to HTML but is much stricter. All tags must be closed, nesting must be correct, and there must be a single root element.
Example
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
<attributes category="personal" priority="high" />
</note>When to use XML?
Document formats: Usage in Office formats (DOCX, XLSX), SVG images, and RSS feeds.
Enterprise Systems: SOAP web services and legacy banking systems often rely on XML for its strict validation and namespace support.
Configuration: Maven (`pom.xml`), Android UI layouts, and Spring configuration.
Tools
Although DevFormat focuses on JSON/YAML, XML can often be converted to these formats for easier modern processing.
- JSON to XML: Convert modern JSON data to XML for legacy systems.