XML: Elements, Attributes & Well-Formedness
XML (eXtensible Markup Language) is a text-based markup language for structured data. Unlike HTML's fixed tag set, XML is extensible -- authors define their own tag names and document structure fit to their specific data.
Elements & Attributes
<book id="42" available="true">
<title>Dune</title>
<author>Frank Herbert</author>
</book>
<!-- book, title, author are ELEMENTS -->
<!-- id and available are ATTRIBUTES on the book element -->Well-Formedness Rules
Exactly one root element containing everything else in the document.
Every opening tag must have a matching closing tag.
Tags must be properly nested, never overlapping.
Tag and attribute names are case-sensitive -- <Book> and <book> are different names.
Escaping Special Characters
<!-- WRONG: < starts a new tag in XML's grammar -->
<note>5 < 10</note>
<!-- CORRECT -->
<note>5 < 10</note>
<!-- For larger blocks of literal content, use CDATA instead: -->
<script><![CDATA[if (a < b) { doSomething(); }]]></script>Well-Formed vs. Valid
Well-formed means the document follows XML's basic syntax rules regardless of content. Valid means it additionally conforms to a specific schema (a DTD or XSD) defining exactly which elements and attributes are allowed and how they nest.
Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free