XML Comments

What is Comment?

Comment is notes or explanation in details about any block of code in XML documents. HTML and XML has similar structure to define comments and use it into XML document or in HTML web page.

Comment doesn’t display any data into web page or can’t read by parser or any other languages. You may write your own comments and there are no any rules to write it, but you must have to follow its syntax only.

You may define any kind of textual explanation in comment like numbers, texts, symbols, calculations, links and code. There is no such fixed position where you place your comment box in XML document after XML declaration, you can write it anywhere in xml document below XML declaration. You can’t place comment in elements attributes.

You may use following syntax to define your comment in XML document.

<!—Comment should be here -->         =     Valid

<!—Comment -- should be here -->      =     Not Valid

Any information you may write in between <!-- and --> considered as comment in above comment syntax. You must not add comment in comment itself.

Note: You can’t use special symbols in comment because many symbols play role while creating XML documents. Like <, L, --, & etc...

Example:

<?xml version="1.0" encoding="UTF-8"?>
<!—Product List and details start-->
<products>
<product id="1001" >
<name>Sony Xperia R1 Dual</name>
<color>Silver</color>
<price>$650.00</price>
<discount>$20.00</discount>
</product>
</products>
<!—Product List and details end-->

Above example explained how you can write your comments in XML document.

Rules to write comment
You can’t write comment inside elements attributes
You must write comment anywhere in XML document after XML declaration on top
You can’t write comment inside comment
You can’t use --, >, <, & and other special symbols which are reserved in XML standard.
You can’t place comment before XML declaration