XML – Comments

  • Post author:
  • Post category:XML
  • Post comments:0 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.

Syntax

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.

Example

Following example demonstrates the use of comments in XML document −

<?xml version = "1.0" encoding = "UTF-8" ?>
<!--Students grades are uploaded by months-->
<class_list>
   <student>
      <name>Dinesh</name>
      <grade>A</grade>
   </student>
</class_list>

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.

Leave a Reply