beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

XML Comments

By Chaitanya Singh | Filed Under: XML Tutorial

XML comment is nothing but a piece of text, that we can include in the XML document to make it more readable. Comments don’t carry data and are used for the understanding purpose purely. For example – You may want to mark a piece of XML data with the XML comment so that anyone who is looking at the XML document can understand the purpose of that data. In this guide, we will learn how to write comments in XML document.

Syntax of XML comment

<!-- This is just a comment. It is optional-->

Whatever written between <!-- and --> will be treated as a comment.

XML comment example

Look at this example, here we have a single comment just before the root element. This comment explains the purpose of the tags that are following the comment. As you can see, the comment improves the readability of the XML document, we can understand the purpose of the tags by reading a piece of text mentioned as a comment.

<?xml version="1.0" encoding="UTF-8" ?>
<!--Employees salary and age details-->
<employees>
 <employee>
   <name>Steve</name>
   <age>34</age>
   <salary>2000$</salary>
 </employee>
 <employee>
   <name>Chaitanya</name>
   <age>31</age>
   <salary>5000$</salary>
 </employee>
</employees>

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap