In this tutorial, You learn below things

  • XML Comments
  • XMl Encoding

XML Comments

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

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

XML Comments example

Following is an example

    XML document for a list of users
    Each user has 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 encoding attribute to have support for an 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