XML Rules

Rule 1: First line contains the XML declaration

It defines the version and the encoding used.

For example:

<?xml version= “1.0” encoding=“ISO-8859-1”?>

Rule 2: All XML elements must have a closing tag

Here is an example of correct syntax:

<body>It is illegal to omit the closing tag.</body>

And this incorrect:

<body>I would never do that?

Rule 3: Tags are case sensitive

Example of correct syntax:

<body>No shouting!</body>

Example of incorrect syntax:

<BoDY>ThIs Is InCoRrEcT.<bODy>

Rule 4: All elements must be properly nested

Correct:

<b><i>This text will be italic and bold.<i><b>

Incorrect:

<b><i>This text is neither italic nor bold.<b><i>

Rule 5: All documents must have a root element

For example:

<root>
	<child> 
		<subchild>...</subchild>
	</child>
</root>

Rule 6:Attribute values must always be in quotes

Correct example:

<note date="02/05/25">

Incorrect example:

<note date=02/05/25>

IBM - About xml syntax