XML Comments

XML comments are just like HTML comments. We know that the comments are used to make codes more understandable other developers.

XML Comments add notes or lines for understanding the purpose of an XML code. Although XML is known as self-describing data but sometimes XML comments are necessary.

Syntax

An XML comment should be written as:

snippet
<!-- Write your comment-->
Note
You cannot nest one XML comment inside the another.

XML Comments Example

Let's take an example to show the use of comment in an XML example:

snippet
<?xml version="1.0" encoding="UTF-8" ?>
<!--Students marks are uploaded by months-->
<students>
   <student>
      <name>Ratan</name>
      <marks>70</marks>
   </student>
   <student>
      <name>Aryan</name>
      <marks>60</marks>
   </student>
 </students>

Rules for adding XML comments

  • Don't use a comment before an XML declaration.
  • You can use a comment anywhere in XML document except within attribute value.
  • Don't nest a comment inside the other comment.
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +