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


<!-- 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

    <user id="1">
     This is single user comments

Single line comments

Comments text is placed in a single-line Syntax:

<!-- Comments text -->

Here is XML single line comments example

    <user id="1">
    <!-- Hello This is single user comments -->

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
    <user id="1">
        <name>john<name><!-- name of employee -->
     <salary>5000</salary> <!-- salary of employee -->

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