Python, lxml and Xpath

https://lxml.de/xpathxslt.html https://www.w3schools.com/xml/xpath_syntax.asp Read a file with xml, convert it to a string from bytes: pip install lxml from lxml import etree as et Make dictionary (duplicate keys, get atr) result: Code: def xml_to_dict(xmlfile): msg = {} count = 1 with open(xmlfile) as r: xml = r.read() print(type(xml)) parser = et.XMLParser(recover=True, collect_ids=True) root = et.fromstring(bytes(xml, encoding=”utf-8″), parser) x = root.xpath(“//*”)# get all #x […]