Comments

Comments are represented by Comment nodes. This interface extends CharacterData and does not add any further methods. It is simply used to identify nodes that represent comments.

When the value of a comment node is written out to XML the delimiter markup, '<!--' and '-->', is added.

Creating comments

A new Comment node can be created using the createComment factory method defined in the Document interface. The following example shows a new comment being created with the value ' my comment ' (note the surrounding spaces, which are used to make the comment easier to read within delimiter markup), then the comment being attached to the end of the document:

// <!-- The End -->

Comment newCommentNode =
             myDoc.createComment( " The End " ); ...

Get XML Companion, The, Third 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.