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

14.16. The Comment class

There's not much to this class: it stores the content in a DOM Comment node.

xml4create.py
# - - - - -   c l a s s   C o m m e n t   - - - - -

class Comment:
    """Represents an XML comment."""


# - - -   C o m m e n t . _ _ i n i t _ _   - - -

    def __init__ ( self, parent, content ):
        """Constructor for a Comment object.
          [ parent is an Element object ->
              parent  :=  parent with a new comment node added with
                          text=content
            return a new Comment object representing that node ]
        """

        #-- 1 --
        # [ parent is an Element ->
        #     self.node  :=  a new DOM Comment node with content=content ]
        self.node  =  parent.doc.node.createComment ( content )

        #-- 2 --
        # [ parent  :=  parent with self.node added as its last or
        #               only child ]
        parent.node.appendChild ( self.node )