code: def getMappingById(self, document, depth=None, element=None,
                         mapping=None, level=1):
          
          if document is not None:
              element = document.documentElement
              mapping = {}
          attr = element._attrs.get('id', None)
          if attr is not None:
              mapping[attr.value] = element
          if depth is None or depth > level:
              level = level + 1
              ELEMENT_NODE = element.ELEMENT_NODE
              for child in element.childNodes:
                  if child.nodeType == ELEMENT_NODE:
                      self.getMappingById(None, depth, child, mapping, level)
          return mapping
docs: 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.