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

<earth>

      <!-- Contains information on countries -->

      <country>Canada</country>

</earth>

Example of non well-formed XML comments

<earth>

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

</earth>

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
Character 

References

&

&amp;

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

Example of well-formed XML entities

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

Output:

<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 ››