def getMappingById(self, document, depth=None, element=None,<EOL>mapping=None, level=<NUM_LIT:1>):
if document is not None:<EOL><INDENT>element = document.documentElement<EOL>mapping = {}<EOL><DEDENT>attr = element._attrs.get('<STR_LIT:id>', None)<EOL>if attr is not None:<EOL><INDENT>mapping[attr.value] = element<EOL><DEDENT>if depth is None or depth > level:<EOL><INDENT>level = level + <NUM_LIT:1><EOL>ELEMENT_NODE = element.ELEMENT_NODE<EOL>for child in element.childNodes:<EOL><INDENT>if child.nodeType == ELEMENT_NODE:<EOL><INDENT>self.getMappingById(None, depth, child, mapping, level)<EOL><DEDENT><DEDENT><DEDENT>return mapping<EOL>
Create an id -> element mapping of those elements within a
           document that define an id attribute. The depth of the search
           may be controlled by using the (1-based) depth argument.