xml Building blocks Comments


Example

Comments in XML look like so:

<!-- This is a comment -->

They can appear in element content or top-level:

<?xml version="1.0"?>
<!-- a comment at the top-level -->
<document>
  <!-- a comment inside the document -->
</document>

Comments cannot appear inside tags or inside attributes:

<element <!-- comment with -- inside --> />

or

<element attr="<!-- comment with -- inside -->"/>

are not well-formed.

The character sequence -- cannot appear in the middle of a comment. This is not well-formed XML:

<!-- comment with -- inside -->

Comments in XML, unlike in other languages such as C++, are part of the data model: they are parsed, forwarded, and visible to the consuming application.