XML Markup Cheatsheet
Quick reference for XML: syntax, elements, attributes, namespaces, special characters, and validation.
| Feature | Description | Example | Category |
|---|---|---|---|
| XML Declaration | Document declaration (optional) | <?xml version="1.0" encoding="UTF-8"?> | Basics |
| Root Element | Single root element required | <root> <!-- content --> </root> | Basics |
| Comment | Add comments to XML | <!-- This is a comment --> | Basics |
| Case Sensitive | Tags are case-sensitive | <Name> different from <name> | Basics |
| Element with Content | Element containing text | <title>XML Guide</title> | Elements |
| Empty Element | Self-closing element | <linebreak /> <image src="pic.jpg" /> | Elements |
| Nested Elements | Elements within elements | <book> <title>XML Basics</title> <author>John Doe</author> </book> | Elements |
| Mixed Content | Text and elements together | <p>This is <b>bold</b> text.</p> | Elements |
| Attributes | Add metadata to elements | <book isbn="123-456" format="hardcover"> | Attributes |
| Attribute Quotes | Attributes must be quoted | <img src="photo.jpg" alt="Photo" /> | Attributes |
| Multiple Attributes | Multiple attributes per element | <person id="1" name="John" age="30" /> | Attributes |
| Default Namespace | Define default namespace | <root xmlns="http://example.com/ns"> <child /> </root> | Namespaces |
| Prefixed Namespace | Use namespace prefix | <root xmlns:custom="http://example.com/ns"> <custom:element /> </root> | Namespaces |
| Multiple Namespaces | Multiple namespace declarations | <root xmlns:a="http://a.com" xmlns:b="http://b.com"> <a:item /> <b:item /> </root> | Namespaces |
| CDATA Section | Unparsed character data | <script> <![CDATA[ if (x < 10) { alert("Hello"); } ]]> </script> | Special |
| Entity References | Predefined entities | < (<) > (>) & (&) " (") ' (') | Special |
| Character Reference | Unicode character codes | © (©) € (€) | Special |
| Processing Instruction | Instructions for applications | <?xml-stylesheet type="text/xsl" href="style.xsl"?> | Special |
| DTD Internal | Internal Document Type Definition | <!DOCTYPE root [ <!ELEMENT root (child+)> <!ELEMENT child (#PCDATA)> ]> | Validation |
| DTD External | External DTD reference | <!DOCTYPE root SYSTEM "schema.dtd"> | Validation |
| XML Schema | Reference XSD schema | <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://example.com schema.xsd"> | Validation |
| Simple Document | Basic XML document structure | <?xml version="1.0"?> <catalog> <book id="1"> <title>XML Basics</title> <price>29.99</price> </book> </catalog> | Basics |
| List Structure | Repeating elements | <products> <product id="1"> <name>Item 1</name> </product> <product id="2"> <name>Item 2</name> </product> </products> | Elements |
| Whitespace | Whitespace handling | <text> Spaces preserved </text> <compact>No extra spaces</compact> | Basics |