XML (eXtensible Markup Language) is a markup specification developed by the W3C for storing and transporting structured data in a text-based, human-readable format. Unlike HTML, which focuses on presentation, XML is designed purely for data representation β it provides strict syntax rules (well-formedness), optional schema validation for structural integrity, and namespace mechanisms for avoiding element conflicts. Key consideration: while XML's flexibility and self-describing nature made it a standard for web services (SOAP), configuration files (Maven, Spring), and document formats (SVG, XHTML), its verbose syntax and parsing overhead have led many modern APIs to favor JSON; however, XML remains essential when schema validation, document processing (XPath/XSLT), and complex hierarchies are required.
What This Cheat Sheet Covers
This topic spans 19 focused tables and 135 indexed concepts, 125 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Core XML Syntax
The building blocks every XML document is made of β elements, attributes, the single root, and proper nesting. Master these and you can read or write any XML by hand; the strict rules here are exactly what make a document "well-formed" before any schema even enters the picture.
| Element | Example | Description | |
|---|---|---|---|
<?xml version="1.0" encoding="UTF-8"?> | β’ Optional first line specifying XML version (1.0 or 1.1) and character encoding (typically UTF-8) β’ the standalone attribute indicates whether external definitions are required (yes or no). | ||
<book>Clean Code</book> | β’ Basic building block consisting of start tag, content, and end tag β’ element names are case-sensitive and must start with a letter or underscore | ||
or <img src="logo.png"/> | β’ Self-closing tag with no content between opening and closing β’ the slash before > is mandatory for well-formedness | ||
<book id="101" lang="en"> | β’ Name-value pair inside a start tag providing metadata about the element β’ attribute values must be quoted (single or double quotes). | ||
<library> <book/></library> | β’ Single top-level element that contains all other elements β’ every well-formed XML document must have exactly one root element | ||
<book> <title>XML Guide</title></book> | β’ Elements contained within other elements creating a hierarchical tree structure β’ elements must be properly nested (no overlapping). | ||
<title>Learning XML</title> | β’ Character data between opening and closing tags β’ whitespace is preserved by default unless processed by an application | ||
<!-- This is a comment --> | β’ Non-parsed text ignored by XML processors β’ comments cannot contain -- and cannot be nested inside other comments |