XML (Extensible Markup Language) is a markup language that defines rules for encoding structured documents using nested tags, attributes, and text content. Developed by the W3C in 1998, XML provides a flexible, self-describing format for representing complex data hierarchies.
Structure and syntax
XML documents consist of elements (tags), attributes, and text content. Every document must have exactly one root element, and every opening tag must have a matching closing tag.
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="fiction">
<title>Neuromancer</title>
<author>William Gibson</author>
<year>1984</year>
</book>
</bookstore>
XML is strict about well-formedness: tags must be properly nested, attribute values must be quoted, and special characters (<, >, &) must be escaped as entities (<, >, &).
Where XML is still used
While JSON has replaced XML for most web APIs, XML remains dominant in several domains:
- Enterprise systems: SOAP web services, XML-RPC, and many banking/financial APIs still use XML exclusively.
- Document formats: XHTML, SVG, RSS/Atom feeds, EPUB, and Office Open XML (
.docx,.xlsx) are all XML-based. - Configuration: Java ecosystem configs (Maven
pom.xml, Spring, Android manifests),.csprojfiles in .NET. - Data standards: Healthcare (HL7/FHIR), publishing (DITA, DocBook), and government data exchanges.
XML vs. JSON
JSON is more compact, maps directly to programming language data structures, and is simpler to parse. XML supports namespaces, schemas (XSD), transformation (XSLT), and querying (XPath/XQuery) — features that matter in enterprise contexts but add complexity.
A JSON object {"name": "Ada"} is 15 characters. The XML equivalent <name>Ada</name> is 16 — but real-world XML with namespaces and attributes is far more verbose.
Parsing approaches
- DOM: Loads the entire document into memory as a tree. Good for small files.
- SAX/StAX: Event-based streaming parsers. Better for large files.
- XPath: Query language for selecting nodes.
//book[@category='fiction']/titleselects all fiction book titles.
Format XML with the XML Formatter, reduce file size with the XML Minifier, or convert between formats with JSON to XML and XML to JSON.