<div dir="ltr"><table><tbody><tr><td class="">
<br></td>
<td class="">
<div>
<div class="" itemprop="description">
<p>I try to make plugin in QGIS Dufour to open and read xml
metadata and then to show some information in metadata i try to parse it
with ElementTree and then show it in QLineEdit, this code i use to open
metadata and parse metadata :</p><pre><code>from PyQt4 import QtCore, QtGui
from ui_testparse import Ui_testparse
import xml.etree.ElementTree as ETree
# create the dialog for zoom to point
class 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('.//{<a href="http://www.isotc211.org/2005/gmd}dateStamp/">http://www.isotc211.org/2005/gmd}dateStamp/</a>'
'{<a href="http://www.isotc211.org/2005/gco}Date'">http://www.isotc211.org/2005/gco}Date'</a>):
print element
self.ui.lineSkala.setText(element)<br><br></code><span style="font-family:verdana,sans-serif">however when i try to run it, it give me a error message, the error message say:</span><br><br><code>Traceback (most recent call last):
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\testparse\testparsedialog.py", line 47, in openxml
self.isiData(openfile)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\testparse\testparsedialog.py", line 56, in isiData
self.parsenow(openteks)
File "C:\Users\Mr.Pakde/.qgis2/python/plugins\testparse\testparsedialog.py", line 64, in parsenow
self.ui.lineSkala.setText(element)
TypeError: QLineEdit.setText(QString): argument 1 has unexpected type 'Element'
Python version:
2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]<br><br></code><span style="font-family:verdana,sans-serif">and xml file i want to parse look like this :</span><br><br><code><gmd:dateStamp>
<gco:Date>2013-12-12</gco:Date><br><br><span style="font-family:verdana,sans-serif">Can someone help me, Thanks in Advance</span><br></code></pre></div></div></td></tr></tbody></table></div>