1
我做插件在QGIS打開和分析來自本地盤或移動硬盤XML,這是代碼我使用Open XML文件:元素樹,解析XML didnt出現在QLineEdit的
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)
和解析XML從那以後,我嘗試使用元素樹,這個代碼我用來從代碼分析上面的XML:
#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)
和XML我想分析有這樣的格式:
<gmd:datestamp>
<gco:Date> XML Date </gco:Date>
我嘗試以顯示LineSkala(lineEdit)在QT XML日期但是當我運行它,它可以打開和讀取XML,但未能顯示XML日期在lineSkala,它只是空白,並沒有給我任何錯誤信息
我想念什麼? 感謝您的幫助提前