Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python QGIS XML插件读取和解析第二次尝试_Python_Xml_Parsing_Qgis - Fatal编程技术网

Python QGIS XML插件读取和解析第二次尝试

Python QGIS XML插件读取和解析第二次尝试,python,xml,parsing,qgis,Python,Xml,Parsing,Qgis,我试着编辑我上次在插件中用来打开和解析xml的代码,我仍然使用元素树,因为它集成在python中,我编辑了这段代码 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__(s

我试着编辑我上次在插件中用来打开和解析xml的代码,我仍然使用元素树,因为它集成在python中,我编辑了这段代码

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)
我尝试用不同的样式更改元素树代码以查看结果

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)
但这2个代码给了我相同的错误信息:

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)]

有人能帮我吗?

您需要传递名称空间:请参阅我尝试使用名称空间,但收到错误消息[UnboundLocalError:分配前引用的局部变量“a”),我打开一个新的问题线程询问此问题