<div dir="ltr">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:<br><br><br><i>from PyQt4 import QtCore, QtGui<br>from ui_testparse import Ui_testparse<br>
import xml.etree.ElementTree as ETree<br># create the dialog for zoom to point<br><br><br>class testparseDialog(QtGui.QDialog):<br> def __init__(self):<br> QtGui.QDialog.__init__(self)<br> # Set up the user interface from Designer.<br>
self.ui = Ui_testparse()<br> self.ui.setupUi(self)<br><br> opendata = self.ui.btnCari<br> QtCore.QObject.connect(opendata, QtCore.SIGNAL('clicked()'),self.openxml)<br><br> def openxml(self, event=None):<br>
<br> #open dialog<br> openfile = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '*.xml')<br><br> self.ui.lineLokasi.setText(openfile)<br><br> #call XML data<br> self.isiData(openfile)<br>
<br> def isiData(self, nmsatu):<br> #open teks with read mode<br> openteks = open(nmsatu, 'r').read()<br><br> self.ui.textXml.setText(openteks)<br><br>#Parse XML from Above<br> self.parsenow(openteks)<br>
<br> def parsenow(self, parse):<br> element = ETree.fromstring(parse)<br> xml_obj = ETree.ElementTree(element)<br> for title_obj in xml_obj.findall('./{gmd#}dateStamp/{gco#}Date'):<br> print element<br>
self.ui.lineSkala.setText(element)<br><br><br></i>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 :<br><br>
<i><gmd:dateStamp><br> <gco:Date>2013-12-12</gco:Date><br> </gmd:dateStamp></i><br><br>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<br>
<br>Can someone teach me?<i><br><br></i><br></div>