'Parse the given dom according to the rules specified
in self.extractors.'

def parse_dom(self, dom):

    result = {}
    for extractor in self.extractors:
        if (extractor.group is None):
            elements = [(extractor.label, element) for element in self.xpath(dom, extractor.path)]
        else:
            groups = self.xpath(dom, extractor.group)
            elements = []
            for group in groups:
                group_key = self.xpath(group, extractor.group_key)
                if (not group_key):
                    continue
                group_key = group_key[0]
                group_key = self.tostring(group_key)
                normalizer = extractor.group_key_normalize
                if (normalizer is not None):
                    if callable(normalizer):
                        try:
                            group_key = normalizer(group_key)
                        except Exception as e:
                            _m = '%s:    unable    to    apply    group_key    normalizer'
                            self._logger.error(_m, self._cname, exc_info=True)
                group_elements = self.xpath(group, extractor.path)
                elements.extend([(group_key, element) for element in group_elements])
        for (group_key, element) in elements:
            for attr in extractor.attrs:
                if isinstance(attr.path, dict):
                    data = {}
                    for field in attr.path.keys():
                        path = attr.path[field]
                        value = self.xpath(element, path)
                        if (not value):
                            data[field] = None
                        else:
                            data[field] = ''.join(value)
                else:
                    data = self.xpath(element, attr.path)
                    if (not data):
                        data = None
                    else:
                        data = attr.joiner.join(data)
                if (not data):
                    continue
                attr_postprocess = attr.postprocess
                if callable(attr_postprocess):
                    try:
                        data = attr_postprocess(data)
                    except Exception as e:
                        _m = '%s:    unable    to    apply    attr    postprocess'
                        self._logger.error(_m, self._cname, exc_info=True)
                key = attr.key
                if (key is None):
                    key = group_key
                elif key.startswith('.'):
                    try:
                        key = self.xpath(element, key)[0]
                    except IndexError:
                        self._logger.error('%s:    XPath    returned    no    items', self._cname, exc_info=True)
                elif key.startswith('self.'):
                    key = getattr(self, key[5:])
                if attr.multi:
                    if (key not in result):
                        result[key] = []
                    result[key].append(data)
                elif isinstance(data, dict):
                    result.update(data)
                else:
                    result[key] = data
    return result
