XML Syntax
The following is a succinct guide for the syntax rules of the eXtensible Markup Language (XML):
-
All XML elements must have a closing tag
<p>This is a paragraph</p>
-
Comments in XML
<!-- This is a comment -->
-
XML tags are case sensitive
<TITLE>This example is incorrect</title> <!-- INCORRECT --> <title>This example is correct</title>
-
XML elements must be properly nested
<strong><em>This text is important and emphasized</strong></em> <!-- INCORRECT because closing em tag appears out of order --> <strong><em>This text is important and emphasized</em></strong>
-
XML documents must have a root element
XML documents must contain one element that is the parent of all other elements. This element is called the root element.
<html> <head> <title>Title</title> </head> </html>
-
XML attribute values must be quoted
<img src=image.png /> <!-- INCORRECT because `image.png` is not quoted --> <img src="image.png" />
-
Special characters in XML
<code>if salary < 1000:</code> <!-- INCORRECT because `<` confused with start of tag --> <code>if salary < 1000:</code>
Entity Symbol Description < < less than > > greater than & & ampersand ' ’ apostrophe " ” quotation mark