In this tutorial, You learn below things writing xml comments

XML Comments

developer writes Comments to describe about line of text or tag in XMl. processor or parser ignores comments during xml parse.

Comments starts with (less than,exclamation symbol and two dashes) <!-- and ends with (two dashes followed by greater than symbol)--> Comments can be single or multi line comments

Multi line comments Syntax:

<!-- multiple lines comments 
text -->

Comment text placed in multiple lines wrapped in comment syntax. Comment text can have string text or tags.

Here is XML multiple line comments example

<users>
    <user id="1">
    <!--
     Hello 
     This is single user comments
     <name>john<name>
     <salary>5000</salary>
      -->
     </user>
</user>

Single line comments

Comments text is placed in a single line Syntax:

<!-- Comments text -->

Here is XML single line comments example

<users>
    <user id="1">
    <!-- Hello This is single user comments -->
     </user>
</user>

Comments can be written

  • Can write in content
  • Not allowed in XML attributes
  • Allowed inside an tag
  • nested comments are not allowed

XML Comments example

Following is an example

<!-- 
    XML document for a list of users
    Each user has information id attribute, name and salary
-->
<users>
    <user id="1">
        <name>john<name><!-- name of employee -->
     <salary>5000</salary> <!-- salary of employee -->
     </user>
</user>

How do I comment out a block of tags in XML?

It is very easy to comment Block of tags with multi line syntax.

Multi line comments starts with <!-- followed by comments, ends with -->

<emps>
    <emp id="1">
    <!--
     Hi 
     Multi line comments in html tags
     <name>eric<name>
     <salary>4000</salary>
      -->
     </emp>
</emps>