XML - Comments

This chapter explains how comments work in XML documents. XML comments are similar to HTML comments. The comments are added as notes or lines for understanding the purpose of an XML code.

Comments can be used to include related links, information, and terms. They are visible only in the source code; not in the XML code. Comments may appear anywhere in XML code.


XML comment has the following syntax −

<!--Your comment-->

A comment starts with <!-- and ends with -->. You can add textual notes as comments between the characters. You must not nest one comment inside the other.


Following example demonstrates the use of comments in XML document −

<?xml version = "1.0" encoding = "UTF-8" ?>
<!--Students grades are uploaded by months-->

Any text between <!-- and --> characters is considered as a comment.

XML Comments Rules

Following rules should be followed for XML comments −

  • Comments cannot appear before XML declaration.
  • Comments may appear anywhere in a document.
  • Comments must not appear within attribute values.
  • Comments cannot be nested inside the other comments.
Kickstart Your Career

Get certified by completing the course

Get Started