Web based School

XML Comments


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>

Previous Next