def METHOD_NAME(self, root, elem):
    ''' Replace marker with elem. '''
    for (p, c) in self.iterparent(root):
        text = ''.join(c.itertext()).strip()
        if not text:
            continue
        # To keep the output from screwing up the
        # validation by putting a <div> inside of a <p>
        # we actually replace the <p> in its entirety.
        if c.text and c.text.strip() == self.marker and len(c) == 0:
            for i in range(len(p)):
                if p[i] == c:
                    p[i] = elem
                    break