Following rules apply to an XML document with valid comment, entitie and reference properties.

XML Comments

Comments in XML starts with “<!--“ contains text and ends with “-->”. The comments are well formed if they follow these rules:

  • They can be put anywhere in the document, except markup of other elements.
  • They are not parsed as character data, and processor may choose to retrieve the comment text.
  •  The string “--” and parameter entity references should be avoided inside comments.

Example of well-formed XML comments


      <!-- Contains information on countries -->



Example of non well-formed XML comments


      <country>Canada</<!--Contains information on countries-->country>


XML Predefined Entities

The predefined XML entities represent the 5 special characters which is processed by all XML processors. The characters are not parsable directly by XML parsers as they are considered as tags. The entities can be declared in DTD, but the replacement text has to be same name> as that of standard definitions. 

It has 3 parts: ‘&’, ‘entity_name’, ‘;’. The 5 entities of XML are given below:

Entity references in XML




< &lt;
“  &quot;
‘     &apos;

Example of well-formed XML entities

<myPocket>"There is &lt; 10 rupees in my pocket"</ myPocket>


<myPocket>"There is < 10 rupees in my pocket"</ myPocket>

 XML Character References

The XML characters references refer to the character’s Unicode code point. It starts with ‘&#’ and ends with ‘;’. The Unicode number of the character is in hexadecimal or decimal. This is essential when introducing special characters like ©, …etc in XML document.

Example of well-formed XML references

Greek letter Omega is represented as &Omega;


›› go to examples ››