print('=== HTMLParser')


class MyHTMLParser(HTMLParser):

    def handle_starttag(self, name, attrs):
        print(('Start element:', name, attrs))

def handle_endtag(self, name):
    print(('End element:', name))

def handle_data(self, data):
    print(('Character data:', repr(data)))

def handle_entityref(self, name):
    self.handle_data(chr(name2codepoint[name]))
htmlparser = MyHTMLParser()
htmlparser.feed(xml)
print('=== XMLParser')
parser = ET.XMLParser()
parser.entity['copy'] = chr(9400)
root = ET.fromstring(xml, parser)
print(ET.tostring(root))
for elem in root:
    print((elem.tag, ' - ', elem.attrib))
for subelem in elem:
    print((subelem.tag, ' - ', subelem.attrib, ' - ', subelem.text))

def start_element(name, attrs):
    print(('Start element:', name, attrs))

def end_element(name):
    print(('End element:', name))

def char_data(data):
    print(('Character data:', repr(data)))
print('=== Expat')
expatparser = expat.ParserCreate()
expatparser.StartElementHandler = start_element
expatparser.EndElementHandler = end_element
expatparser.CharacterDataHandler = char_data
expatparser.Parse(xml)
Анализ XML с помощью (X)HTML-сущностей