Bookmark and Share

XML Comment

A comment is used to leave a note or to temporarily edit out a portion of XML code. Although XML is supposed to be self-describing data, you may still come across some instances where an XML comment might be necessary.

Advertise on Tizag.com

XML Comment Syntax

XML comments have the exact same syntax as HTML comments. Below is an example of a notation comment that should be used when you need to leave a note to yourself or to someone who may be viewing your XML.

XML Code:

<?xml version="1.0" encoding="ISO-8859-15"?>
<!-- Students grades are updated bi-monthly -->
<class_list>
	<student>
		<name>Robert</name>
		<grade>A+</grade>
	</student>
	<student>
		<name>Lenard</name>
		<grade>A-</grade>
	</student>
</class_list>

XML Commenting out XML

For many different reasons, sometimes you might want to temporarily remove some XML code from your XML document. XML Comments let you do this easily, as this example below shows.

XML Code:

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

<class_list>
	<student>
		<name>Robert</name>
		<grade>A+</grade>
	</student>
<!--
	<student>
		<name>Lenard</name>
		<grade>A-</grade>
	</student> 
-->
</class_list>
Bookmark and Share




Download Tizag.com's XML Book

If you would rather download the PDF of this tutorial, check out our XML eBook from the Tizag.com store.

Found Something Wrong in this Lesson?

Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!

Advertise Here

More Tutorials!
Microsoft Office Tutorials Artist Tutorials