I try edited code i use last time in plugin to open and parse xml, i still use Element Tree because it integrated in python, this code i edit
from PyQt4 import QtCore, QtGui
from ui_latih import Ui_latih
import xml.etree.ElementTree as ETree
# create the dialog for zoom to point
class latihDialog(QtGui.QDialog):
def __init__(self):
QtGui.QDialog.__init__(self)
# Set up the user interface from Designer.
self.ui = Ui_latih()
self.ui.setupUi(self)
cariButton = self.ui.btnCari
QtCore.QObject.connect(cariButton, QtCore.SIGNAL('clicked()'),self.cari)
def cari(self, event=None):
#open dialog
filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '*.xml')
self.ui.lineFile.setText(filename)
#panggil isi data
self.isiDataFile(filename)
def isiDataFile(self, nmfile):
#buka dengan open mode baca
teksFile = open(nmfile, 'r').read()
self.ui.textFile.setText(teksFile)
#parse XML FIle
self.parsethis(teksFile)
def parsethis(self, parse):
element = ETree.fromstring(parse)
xml_obj = ETree.ElementTree(element)
for title_obj in xml_obj.findall('.//gco:Integer'):
self.ui.lineSkala.setText(element)
I try change element tree code with different style to see the result
def parsethis(self, parse):
doc = ETree.fromstring(parse)
for elem in doc.findall('Default_Config/gco:Integer'):
a=elem.tag, elem.text
self.ui.lineSkala.setText(a)
But this 2 code give me same error message :
File "C:\PROGRA~1\QGISDU~1\apps\Python27\lib\xml\etree\ElementPath.py", line 83, in xpath_tokenizer
raise SyntaxError("prefix %r not found in prefix map" % prefix)
SyntaxError: prefix 'gco' not found in prefix map
Python version:
2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]
Can Someone Help me please?