====== Esplorare un documento xml con xml.etree.ElementTree ====== Alcune istruzioni esemplificative (cf. [[http://docs.python.org/2/library/xml.etree.elementtree.html]]): import xml.etree.ElementTree as ET tree=ET.parse('testi/ldt-1.5.xml') root=tree.getroot() print(root) parole=root.findall('.//word') print(len(parole)) forme_di_populor=root.findall(".//word[@lemma='populor1']") for i in forme_di_populor: print(i.tag) for i in forme_di_populor: print(i.attrib) for i in forme_di_populor: print(i.text) for i in forme_di_populor: print(i.attrib['form']) ---- Come ricostruire il testo in forma di lista: import xml.etree.ElementTree as ET tree=ET.parse('testi/ldt-1.5.xml') root=tree.getroot() parole=root.findall('.//word') testo=[i.attrib['form'].lower() for i in parole] print(testo[:500]) #mostra le prime 500 parole unita'