[Qgis-user] change element into Qstring in ElementTree

Suryo Miles suryomiles666 at gmail.com
Mon Apr 28 16:04:00 PDT 2014


I try to make QGIS plugin to open and show metadata information in xml
format i use this code to open metadata from drive and show it in UI:













































*from PyQt4 import QtCore, QtGuifrom ui_testparse import Ui_testparseimport
xml.etree.ElementTree as ETree# create the dialog for zoom to pointclass
testparseDialog(QtGui.QDialog):    def __init__(self):
QtGui.QDialog.__init__(self)        # Set up the user interface from
Designer.        self.ui = Ui_testparse()
self.ui.setupUi(self)        opendata = self.ui.btnCari
QtCore.QObject.connect(opendata,
QtCore.SIGNAL('clicked()'),self.openxml)    def openxml(self,
event=None):        #open dialog        openfile =
QtGui.QFileDialog.getOpenFileName(self, 'Open File', '*.xml')
self.ui.lineLokasi.setText(openfile)        #call XML data
self.isiData(openfile)    def isiData(self, nmsatu):        #open teks with
read mode        openteks = open(nmsatu, 'r').read()
self.ui.textXml.setText(openteks)#Parse XML from Above
self.parsenow(openteks)    def parsenow(self, parse):        element =
ETree.fromstring(parse)        xml_obj = ETree.ElementTree(element)
for title_obj in
xml_obj.findall('./{gmd#}dateStamp/{gco#}Date'):            print
element            self.ui.lineSkala.setText(element)*But the value i want
to show didn't appear in QLineEdit (LineSkala), i dont get any error
message, it just blank, xml i want to parse look like this :



*<gmd:dateStamp>      <gco:Date>2013-12-12</gco:Date>   </gmd:dateStamp>*

someone in forum tell me i must change element in print element to a
QString so QLineEdit can read it and show it, but i didn't know how to do
it, i really newbie in python

Can someone teach me?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20140429/aaab375c/attachment.html>


More information about the Qgis-user mailing list