An XML document is said to be well formed if it follows it’s syntax rules very closely. The rules that must apply to an XML document are listed below:

All XML elements must have closing tags



<title>Harry Potter series</title>



XML tags are case-sensitive

Opening and closing tags must be written in same case.


<title>Harry Potter series</title> <!--- Correct --->

<title>Harry Potter series</Title> <!--- Not correct --->

XML tags must be properly nested

Unlike HTML, XML is sensitive to the order of tags.


<b><i>See the order of tags</b></i> //Valid in HTML but invalid in XML.

XML documents must have the root element

The root element s the parent to all other elements in the document.







XML attributes are set in name:value pair

The name:value pair gives more information on the tag itself. The value should be quoted as shown below.


<book type=”fiction”>

<title>Harry Potter series</title>



Parsing properly the predefined entities

If a XML document has predefined entity such as “<”, “>” etc... which will be interpreted by parser as start or end of new element, it has to be replaced with entity references. The entity references and it’s symbol are listed below:

  • < - &lt;
  • > - &gt;
  • & - &amp;
  • ‘ - &apos;
  • “ - &quot;


<p>Sanju & Geetha are friends </p> <!--- Not correct --->

<p>Sanju &amp; Geetha are friends </p> <!--- Not correct --->

Properly adding comments

To add a comment <!---- comment here ----> symbol is used as in HTML.

Preservation of white spaces

White spaces are preserved in XML and not truncated as in HTML.


<p>May     June</p> is not same as

<p>May  June</p>

New line storage

A new line is stored as LF.


›› go to examples ››