Name

Comment

Synopsis

This object contains the text of an XML comment (everything between the opening <!-- and closing -->). It inherits from CharacterData.

Tip

The DOM specification does not require XML parsers to preserve the original document comments after the document is parsed. Some implementations strip comments as part of the parsing process.

Java example

// Create a comment
Comment ndComment = doc.createComment("Document was parsed by DOM utility.");
     
// and add it to the document
doc.appendChild(ndComment);

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.