XML Markup Cheatsheet

Quick reference for XML: syntax, elements, attributes, namespaces, special characters, and validation.

FeatureDescriptionExampleCategory
XML DeclarationDocument declaration (optional)<?xml version="1.0" encoding="UTF-8"?>Basics
Root ElementSingle root element required<root> <!-- content --> </root>Basics
CommentAdd comments to XML<!-- This is a comment -->Basics
Case SensitiveTags are case-sensitive<Name> different from <name>Basics
Element with ContentElement containing text<title>XML Guide</title>Elements
Empty ElementSelf-closing element<linebreak /> <image src="pic.jpg" />Elements
Nested ElementsElements within elements<book> <title>XML Basics</title> <author>John Doe</author> </book>Elements
Mixed ContentText and elements together<p>This is <b>bold</b> text.</p>Elements
AttributesAdd metadata to elements<book isbn="123-456" format="hardcover">Attributes
Attribute QuotesAttributes must be quoted<img src="photo.jpg" alt="Photo" />Attributes
Multiple AttributesMultiple attributes per element<person id="1" name="John" age="30" />Attributes
Default NamespaceDefine default namespace<root xmlns="http://example.com/ns"> <child /> </root>Namespaces
Prefixed NamespaceUse namespace prefix<root xmlns:custom="http://example.com/ns"> <custom:element /> </root>Namespaces
Multiple NamespacesMultiple namespace declarations<root xmlns:a="http://a.com" xmlns:b="http://b.com"> <a:item /> <b:item /> </root>Namespaces
CDATA SectionUnparsed character data<script> <![CDATA[ if (x < 10) { alert("Hello"); } ]]> </script>Special
Entity ReferencesPredefined entities&lt; (<) &gt; (>) &amp; (&) &quot; (") &apos; (')Special
Character ReferenceUnicode character codes&#169; (©) &#8364; (€)Special
Processing InstructionInstructions for applications<?xml-stylesheet type="text/xsl" href="style.xsl"?>Special
DTD InternalInternal Document Type Definition<!DOCTYPE root [ <!ELEMENT root (child+)> <!ELEMENT child (#PCDATA)> ]>Validation
DTD ExternalExternal DTD reference<!DOCTYPE root SYSTEM "schema.dtd">Validation
XML SchemaReference XSD schema<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://example.com schema.xsd">Validation
Simple DocumentBasic XML document structure<?xml version="1.0"?> <catalog> <book id="1"> <title>XML Basics</title> <price>29.99</price> </book> </catalog>Basics
List StructureRepeating elements<products> <product id="1"> <name>Item 1</name> </product> <product id="2"> <name>Item 2</name> </product> </products>Elements
WhitespaceWhitespace handling<text> Spaces preserved </text> <compact>No extra spaces</compact>Basics