How To Comment In XML Tag Block or Single Line?


XML comments are very useful in order to explain the XML tags. Also if we want to test some XML code with and without we can use comments to enable or disable a single line or XML tag block. XML has similar syntax and terms to the HTML and also comment term is the same.

Comment XML Block

As XML is a hierarchical language there may be a lot of tags which are parents and children of others. This named XML tag block. We can command XML tag block which consists of multiple XML tags with the <!-- CODEBLOCK -->

We can see in the following example we will comment on the second student which is in red. This means the second student named Ahmet will not processes by XML processors.

<?xml version="1.0" encoding="ISO-8859-15"?>

<class>
    <student>
        <name>İsmail</name>
        <grade>A+</grade>
    </student>
<!--
    <student>
        <name>Ahmet</name>
        <grade>A-</grade>
    </student> 
-->
</class>

Comment Single Line

We can comment on a single line with the <!-- SINGLELINE -->. This will only affect the single line and do not comment on upper or lower lines.

<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- Student list can be stored here -->
<class>
    <student>
        <name>İsmail</name>
        <grade>A+</grade>
    </student>
    <student>
        <name>Ahmet</name>
        <grade>A-</grade>
    </student>
</class>

LEARN MORE  What Is SOAP (Simple Object Access Protocol)?

Leave a Comment