XML - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

XML Comments

XML Comments

shape Description

A comment is a software engineer discernable clarification or comment in the source code of a PC program. They are included with the reason for making the source code less demanding for people to comprehend, and are by and large disregarded by compilers and translators. The punctuation of remarks in different programming dialects changes significantly. XML Comments are the statements used in the XML code to make the user to understand what is happening in the source code given to the compiler without reading the actual code. XML Comments makes the new user to learn the language easily.

Syntax

shape Description

The syntax of a comment will have left angle bracket >, followed by an exclamation point !, followed by two dashes --, followed the comment itself, followed by two dashes --, followed by a right angle bracket >. XML Comments syntax will be as follows. [xml]<!-- This is a comment -->[/xml] In the above syntax, placing of two dashes in between the comment is not allowed. [xml]<!-- This is a -- comment -->[/xml] The above format is not allowed if given a whitespace between the two dashes is strange, but allowed. [xml]<!-- This is a - - comment -->[/xml]

Comment Rules

While using comments in XML, following rules should be followed.
  • Before the declaration of XML document, comments should not be used.
  • Comments can be used anywhere in a XML Document.
  • Inside the values of attribute, Comments should not be used.
  • Never use multi-line XML Comments in nested form because it causes confusion when opening and closing of nested comment.

shape Example

Below is an example for XML Comments. [xml] <?xml version="1.0" encoding="utf-8"?> <!-- In this collection, we will keep each title "as is" --> <videos> <video> <title>The Distinguished Gentleman</title> <director>Jonathan Lynn</director> <length>112 Minutes</length> <format>DVD</format> <rating>R</rating> </video> <video> <title>Her Alibi</title> <director>Bruce Beresford</director> <length>94 Mins</length> <format>DVD</format> <rating>PG-13</rating> </video> </videos> [/xml] The comments do not occupy any space. Comments are infrequently handled in different approaches to create documentation outer to the source code itself by documentation generators, or utilized for reconciliation with source code administration frameworks and different sorts of outside programming instruments.

Java Comments

shape Description

Java Comments represent the ail and description of a program.While writing any code in any technology developer will mention comments to understand the coding lines, compiler will not execute those comments and memory will not be allocated to an application. The main advantage of Java Comments are readability. Comments can be defined as three ways in Java as follows. Following is an example which describes what is the purpose of Java Comments. [java]//simple program to check whether year is leap year or not import java.util.Scanner; public class leapyear { private static Scanner input; /**A leap year in the Gregorian calendar has an extra day for February. *A leap year has 366 days. * * Algorithm to find a leap year * ------------------------------- * if year % 400 = 0, leap year * else if year % 100 = 0, not a leap year * else if year % 4 = 0, leap year * else, not a leap year */ public static void main(String args[]) { int year; System.out.println("Enter the year."); Scanner s=new Scanner(System.in); year = s.nextInt(); if(year%400==0 || year%100 ==0 || year%4==0){ System.out.println("Entered number is leap year."); } else{ System.out.println("it is not a leap year."); } } }[/java] Output: Now compile the code result will be as follows. [java]Enter the year. 2016 Entered number is leap year.[/java]

Summary

shape Key Points

  • XML Comments are the statements which makes the user to understand the code easily.
  • Should not be used before the declaration of XML document.