https://www.w3schools.com/XML/plant_catalog.xml from __future__ import print_function import os, sys, time from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class Window (QMainWindow) : def __init__ (self) : super (Window, self).__init__ () self.tree = QTreeWidget () self.setCentralWidget (self.tree) self.scanXml ("Downloads/plant_catalog.xml") # https://www.w3schools.com/XML/plant_catalog.xml def scanXml (self, fileName) : f = QFile (fileName) if f.open (QFile.ReadOnly) : r = QXmlStreamReader (f) target = self.tree while not r.atEnd () : if r.isStartElement() : node = QTreeWidgetItem (target) node.setText (0, r.name()) target = node if r.isEndElement() : target = target.parent () if r.isCharacters () : t = r.text().strip() if t != "" : node = QTreeWidgetItem (target) node.setText (0, t) r.readNext () if __name__ == "__main__" : appl = QApplication (sys.argv) win = Window () win.show () appl.exec_ () from __future__ import print_function import os, sys, time from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * f = QFile ("Downloads/plant_catalog.xml") n = 0 if f.open (QFile.ReadOnly) : r = QXmlStreamReader (f) while not r.atEnd () : if r.isStartElement() : print (" "*3*n + "<" + r.name() + ">") n = n + 1 if r.isEndElement() : n = n - 1 print (" "*3*n + "") if r.isCharacters () : t = r.text().strip() if t != "" : print (" "*3*n + t) r.readNext ()