Parse XML data

def parse(self, xml_data):
        """ Parse XML data """

        # parse tree
        if isinstance(xml_data, string_types):
            # Presumably, this is textual xml data.
            try:
                root = ET.fromstring(xml_data)
            except StdlibParseError as e:
                raise ParseError(str(e))
        else:
            # Otherwise, assume it has already been parsed into a tree
            root = xml_data

        # get type
        if 'type' in root.attrib:
            self.kind = root.attrib['type']

        # parse component
        for c1 in root:

            # <id>
            if c1.tag == 'id':
                self.id = c1.text

            # <updatecontact>
            elif c1.tag == 'updatecontact' or c1.tag == 'update_contact':
                self.update_contact = c1.text

            # <metadata_license>
            elif c1.tag == 'metadata_license':
                self.metadata_license = c1.text

            # <releases>
            elif c1.tag == 'releases':
                for c2 in c1:
                    if c2.tag == 'release':
                        rel = Release()
                        rel._parse_tree(c2)
                        self.add_release(rel)

            # <reviews>
            elif c1.tag == 'reviews':
                for c2 in c1:
                    if c2.tag == 'review':
                        rev = Review()
                        rev._parse_tree(c2)
                        self.add_review(rev)

            # <screenshots>
            elif c1.tag == 'screenshots':
                for c2 in c1:
                    if c2.tag == 'screenshot':
                        ss = Screenshot()
                        ss._parse_tree(c2)
                        self.add_screenshot(ss)

            # <provides>
            elif c1.tag == 'provides':
                for c2 in c1:
                    prov = Provide()
                    prov._parse_tree(c2)
                    self.add_provide(prov)

            # <requires>
            elif c1.tag == 'requires':
                for c2 in c1:
                    req = Require()
                    req._parse_tree(c2)
                    self.add_require(req)

            # <kudos>
            elif c1.tag == 'kudos':
                for c2 in c1:
                    if not c2.tag == 'kudo':
                        continue
                    self.kudos.append(c2.text)

            # <keywords>
            elif c1.tag == 'keywords':
                for c2 in c1:
                    if not c2.tag == 'keyword':
                        continue
                    self.keywords.append(c2.text)

            # <categories>
            elif c1.tag == 'categories':
                for c2 in c1:
                    if not c2.tag == 'category':
                        continue
                    self.categories.append(c2.text)

            # <custom>
            elif c1.tag == 'custom':
                for c2 in c1:
                    if not c2.tag == 'value':
                        continue
                    if 'key' not in c2.attrib:
                        continue
                    self.custom[c2.attrib['key']] = c2.text

            # <project_license>
            elif c1.tag == 'project_license' or c1.tag == 'licence':
                self.project_license = c1.text

            # <developer_name>
            elif c1.tag == 'developer_name':
                self.developer_name = _join_lines(c1.text)

            # <name>
            elif c1.tag == 'name' and not self.name:
                self.name = _join_lines(c1.text)

            # <pkgname>
            elif c1.tag == 'pkgname' and not self.pkgname:
                self.pkgname = _join_lines(c1.text)

            # <summary>
            elif c1.tag == 'summary' and not self.summary:
                self.summary = _join_lines(c1.text)

            # <description>
            elif c1.tag == 'description' and not self.description:
                self.description = _parse_desc(c1)

            # <url>
            elif c1.tag == 'url':
                key = 'homepage'
                if 'type' in c1.attrib:
                    key = c1.attrib['type']
                self.urls[key] = c1.text

            elif c1.tag == 'icon':
                key = c1.attrib.pop('type', 'unknown')
                c1.attrib['value'] = c1.text
                self.icons[key] = self.icons.get(key, []) + [c1.attrib]