In this tutorial, You learn below things

  • XML Comments
  • XML Encoding

XML Comments

Comments are written for a developer to describe the line of text or tag in XML. These are ignored by the processor or parser during XML parse.

Comments start with (less than, exclamation symbol and two dashes) <!-- and end 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 is 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 content
  • Not allowed in XML attributes
  • Allowed inside a tag
  • nested comments are not allowed

XML Comments Example

Following is an example

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

XML Encoding

encoding used to represent the character set supported by actual xml content.

Default XML encoding is UTF-8

XML file declaration contains an encoding attribute to have support for character content in XML.

Here is an xml declaration

<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>

encoding can be UTF-8: used 8 bytes to represent characters, UTF-16: 16 bytes to represent characters