XML has strict syntax rules that must be followed to create well-formed XML documents. Unlike HTML, XML is case-sensitive and every opening tag must have a closing tag.
XML
Beginner
8 min read
XML Syntax Rules
Example
<?xml version="1.0" encoding="UTF-8"?>
<!-- XML Syntax Rules -->
<!-- 1. Must have a root element -->
<root>
<!-- 2. Tags are case-sensitive: <Name> != <name> -->
<Name>Alice</Name>
<name>Bob</name>
<!-- 3. All tags must be closed -->
<self-closing-tag /> <!-- self-closing -->
<normal>content</normal>
<!-- 4. Attributes must be quoted -->
<item id="1" color="red">Value</item>
<!-- 5. Proper nesting required -->
<!-- WRONG: <a><b></a></b> -->
<!-- RIGHT: -->
<a><b></b></a>
<!-- 6. Special characters must be escaped -->
<comparison>5 < 10 && 10 > 5</comparison>
<!-- < = < > = > & = & " = " ' = ' -->
<!-- 7. Comments -->
<!-- This is a comment -->
</root>