'Parse an html file and return an mdn object.
Args:
htmlfile: A file-like object that should parse with lxml html parser.'

def parse(self, htmlfile):

    page = htmlfile.read()
    tree = html.fromstring(page)
    if self._is_obsolete(tree):
        return None
    title = tree.xpath("//meta[@property='og:title']/@content")[0]
    article = tree.xpath("//article[contains(@id,'wikiArticle')]")
    summary = ''
    if article:
        summary_nodes = tree.xpath("//h2[contains(@id,'Summary')]/following-sibling::p[1]")
        for summary_el in summary_nodes:
            for tag in summary_el.xpath('//*[@class]'):
                tag.attrib.pop('class')
            summary += re.sub('<[^<]+?>', '', etree.tostring(summary_el).strip())
    if (not summary):
        summary_el = tree.xpath("//meta[@property='og:description']/@content")
        if summary_el:
            summary = summary_el[0]
    if (not summary):
        see_also_el = tree.xpath("//h3[contains(@id,'See_also')]")
        if see_also_el:
            elements = tree.xpath("//h3[contains(@id,'See_also')]/following-sibling::ul[1]")
            for element in elements:
                for tag in element.xpath('//*[@class]'):
                    tag.attrib.pop('class')
                summary = re.findall('title="([^"]*)"', etree.tostring(element).strip())
            summary = summary[0].strip()
    codesnippet = ''
    syntax_header = tree.xpath("//h2[contains(@id,'Syntax')]")
    if syntax_header:
        elements = tree.xpath("//h2[contains(@id,'Syntax')]/following-sibling::pre[1]")
        for element in elements:
            for tag in element.xpath('//*[@class]'):
                tag.attrib.pop('class')
            codesnippet += re.sub('<[^<]+?>', '', etree.tostring(element).strip())
    articletype = ''
    exampledesc = ''
    example = ''
    url = tree.xpath("//meta[@property='og:url']/@content")[0]
    if ('Web/API' in url):
        example_header = tree.xpath("//h2[contains(@id,'Example')][position()=1]")
        if example_header:
            html_example_header = tree.xpath("//h2[contains(@id,'Example')][position()=1]/following-sibling::h3[contains(@id,'HTML_Content')]")
            js_example_header = tree.xpath("//h2[contains(@id,'Example')][position()=1]/following-sibling::h3[contains(@id,'JavaScript_Content')]")
            if (html_example_header and js_example_header):
                example = {}
                example['HTML    Content'] = ''
                elements = tree.xpath("//h2[contains(@id,'Example')][position()=1]/following-sibling::h3[contains(@id,'HTML_Content')]/following-sibling::pre[1]")
                for element in elements:
                    for tag in element.xpath('//*[@class]'):
                        tag.attrib.pop('class')
                    example['HTML    Content'] += re.sub('<[^<]+?>', '', etree.tostring(element).strip())
                example['JavaScript    Content'] = ''
                elements = tree.xpath("//h2[contains(@id,'Example')][position()=1]/following-sibling::h3[contains(@id,'JavaScript_Content')]/following-sibling::pre[1]")
                for element in elements:
                    for tag in element.xpath('//*[@class]'):
                        tag.attrib.pop('class')
                    example['JavaScript    Content'] += re.sub('<[^<]+?>', '', etree.tostring(element).strip())
            else:
                example = ''
                example_header = tree.xpath("//h2[contains(@id,'Example')]")
                if example_header:
                    elements = tree.xpath("//h2[contains(@id,'Example')]/following-sibling::pre[1]")
                    for element in elements:
                        for tag in element.xpath('//*[@class]'):
                            tag.attrib.pop('class')
                        example += re.sub('<[^<]+?>', '', etree.tostring(element).strip())
                elements = tree.xpath("//h2[contains(@id,'Example')]/following-sibling::p[1]")
                for element in elements:
                    for tag in element.xpath('//*[@class]'):
                        tag.attrib.pop('class')
                    exampledesc += re.sub('<[^<]+?>', '', etree.tostring(element).strip())
    if ('Error' in htmlfile.name):
        articletype = 'Error'
        whatWentWrong_summary = ''
        whatWentWrong = tree.xpath("//h2[contains(@id,'What_went_wrong')]/following-sibling::p[1]")
        for element in whatWentWrong:
            for tag in element.xpath('//*[@class]'):
                tag.attrib.pop('class')
            whatWentWrong_summary += re.sub('<[^<]+?>', '', etree.tostring(element).strip())
        if whatWentWrong_summary:
            summary = whatWentWrong_summary
        exampleGood = ''.join(tree.xpath("//h3[contains(@id,'Valid_cases')]/following-sibling::pre/text()"))
        exampleBad = ''.join(tree.xpath("//h3[contains(@id,'Invalid_cases')]/following-sibling::pre/text()"))
        exampleGood = re.sub('<[^<]+?>', '', exampleGood)
        exampleBad = re.sub('<[^<]+?>', '', exampleBad)
        if exampleGood:
            exampleGood = ('Valid    Cases:\n' + exampleGood)
        if exampleBad:
            exampleBad = ('Invalid    Cases:\n' + exampleGood)
        if (exampleBad or exampleGood):
            codesnippet = ((exampleBad + '\n') + exampleGood)
    if any(((wiki in htmlfile.name) for wiki in ['Functions.', 'Classes.', 'Statements.', 'Operators.'])):
        articletype = htmlfile.name.split('.')[0].split('/')[1]
        desc_header = tree.xpath("//h2[contains(@id,'Description')]")
        if desc_header:
            elements = tree.xpath("//h2[contains(@id,'Description')]/following-sibling::p[1]")
            for element in elements:
                for tag in element.xpath('//*[@class]'):
                    tag.attrib.pop('class')
                exampledesc += re.sub('<[^<]+?>', '', etree.tostring(element).strip())
            elements = tree.xpath("//h2[contains(@id,'Description')]/following-sibling::pre[1]")
            for element in elements:
                for tag in element.xpath('//*[@class]'):
                    tag.attrib.pop('class')
                example += re.sub('<[^<]+?>', '', etree.tostring(element).strip())
        else:
            elements = tree.xpath("//h2[contains(@id,'Examples')]/following-sibling::p[1]")
            for element in elements:
                for tag in element.xpath('//*[@class]'):
                    tag.attrib.pop('class')
                exampledesc += re.sub('<[^<]+?>', '', etree.tostring(element).strip())
            elements = tree.xpath("//h2[contains(@id,'Examples')]/following-sibling::pre[1]")
            for element in elements:
                for tag in element.xpath('//*[@class]'):
                    tag.attrib.pop('class')
                example += re.sub('<[^<]+?>', '', etree.tostring(element).strip())
    print ((title + ('    ' * 30)) + '\r'),
    mdn = MDN()
    mdn.title = title
    mdn.summary = summary
    mdn.codesnippet = codesnippet
    mdn.exampledesc = exampledesc
    mdn.example = example
    mdn.articletype = articletype
    return mdn
