Next / Previous / Contents / TCC Help System / NM Tech homepage

7. Features of the etree module

The etree contains numerous functions and class constructors.

7.1. The Comment() constructor

To create a comment node, use this constructor:


The text to be placed within the comment. When serialized back into XML form, this text will be preceded by “<!-- ” and followed by “ -->”. Note that one space will be added around each end of the text you supply.

The return value is an instance of the Comment class. Use the .append() method on the parent element to place the comment into your document.

For example, suppose bodyElt is an HTML body element. To add a comment under this element containing string s, you would use this code:

newComment = etree.Comment(s)