XML — Comments
Basic Comment
<!-- This is a comment -->
Multi-line Comment
<!--
This is a multi-line comment.
It can span multiple lines.
-->
Comment Rules
- Cannot contain
-- - Cannot be inside declarations
- Must have a space after
<!--
<!-- Correct -->
<!-- This is a comment -->
<!-- Incorrect -->
<!--This contains -- inside-->
Practical Comments
<?xml version="1.0" encoding="UTF-8"?>
<!-- Book catalog - Last updated: 2025-01-01 -->
<catalog>
<!-- Fiction books -->
<category name="fiction">
<book>
<!-- TODO: Add more details -->
<title>My Book</title>
</book>
</category>
</catalog>
Conditional Sections
<![CDATA[This content is ignored by some parsers]]>
Mini Practice
- Add single-line comments
- Add multi-line comments
- Comment out a section
- Use comments for documentation
Up Next
Continue with Namespaces — avoiding naming conflicts.
Related Topics
Frequently Asked Questions about Comments
What is Comments in XML?
Comments is a fundamental concept in XML. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Comments?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Comments.
Why is Comments important in XML?
Comments is essential for XML development. Understanding this concept will help you write better code and solve real-world problems more effectively.