In this tutorial you will learn about the XML Comment and its application with practical example.
XML comments begin with <!--
and ends with -->
. Like any other programming language XML Comments is used to add annotations or remarks to enhance the readability of the XML Code for the programmers. Comments can be placed anywhere in an XML document.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?xml version="1.0" encoding="iso-8859-1"?> <!-- Here is a comment --> <inbox> <message id="1"> <from>John</from> <subject>Test Message 1</subject> <body>Hello John!</body> </message> <message id="2"> <from>Chris</from> <subject>Test Message 2</subject> <body>Hello John!</body> </message> </inbox> |
Commenting XML Element:
Sometimes we may want to temporarily remove some XML code in our XML document. XML Comments allow us to do this easily.
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0" encoding="iso-8859-1"?> <inbox> <!-- <message id="1"> <from>John</from> <subject>Test Message 1</subject> <body>Hello John!</body> </message> --> <message id="2"> <from>Chris</from> <subject>Test Message 2</subject> <body>Hello John!</body> </message> </inbox> |