How to Comment out a Line in XML

XML provides a markup language for storing data and conveying it from one location to another. Like HTML, it uses plain text you can edit in any application that writes TXT files. Unlike HTML, XML tags provide descriptive detail about content rather than visual instructions for displaying it. As you define XML tags to characterize a set of information, you can use comments to serve two purposes within your work: to explain it, and to omit parts of it from the code that other applications process. If you already know HTML comment syntax, you also know the XML equivalent.

XML, extensible markup language
"XML" stands for "Extensible Markup Language."
credit: Raywoo/iStock/Getty Images

Single-Line Comment

Step

Insert your cursor at the beginning of a line you want to comment out. Type a less-than symbol followed by an exclamation point and two dashes.

Step

Move your cursor to the end of the line. Type two dashes followed by a greater-than symbol. If your line consists of the statement "Use this section to build a description of adoptable cats," it looks like this with both comment tags in place:

Step

Step

Read your comment to verify that it doesn't contain any instances of two consecutive dashes other than in its opening and closing comment tags. Consecutive dashes trigger a false end-of-comment signal that disrupts your syntax.

Commented Section

Step

Insert your cursor on a blank line above the section of XML code you want to comment out. Type a less-than symbol followed by an exclamation point and two dashes.

Step

Move your cursor to a blank line after the section of XML code. Type two dashes followed by a greater-than symbol. With comments in place, a section of XML code looks like this:

Step

Step

Read your commented section to verify that it doesn't contain a comment within the lines you commented out. Nested comments constitute an error in XML.