[[pyqt_xml]]
 

https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/tiger.svg

 
from __future__ import print_function
 
import os, sys, time
from PyQt4.QtCore import *
from PyQt4.QtGui  import *
 
class Window (QMainWindow) :
    def __init__ (self) :
        super (Window, self).__init__ ()
 
        self.tree = QTreeWidget ()
        self.setCentralWidget (self.tree)
        self.scanXml ("Downloads/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().toString())
                 target = node
              if r.isEndElement() :
                 target = target.parent ()  
              if r.isCharacters () :
                 t = r.text().toString().simplified()
                 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 PyQt4.QtCore import *
from PyQt4.QtGui  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().toString() + ">")
           n = n + 1
        if r.isEndElement() :
           n = n - 1
           print (" "*3*n + "</" + r.name().toString() + ">")
        if r.isCharacters () :
           t = r.text().toString().simplified()
           if t != "" :
              print (" "*3*n + t)
        r.readNext ()
 
pyqt_xml.txt · Last modified: 2018/10/17 10:51 by 147.32.8.115
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki