[Qgis-user] QGIS Plugin to open and parse xml metadata
    Suryo Miles 
    suryomiles666 at gmail.com
       
    Mon Mar 24 09:45:34 PDT 2014
    
    
  
I make plugin in QGIS to open and read XML file, then parse it and show
scale map from it, its a big xml file and line with scale information have
format like this
<gmd:denominator><gco:Integer>ScaleValue</gco:Integer></gmd:denominator>
and i try code like this to open xml file and then parse it:
from PyQt4 import QtCore, QtGuifrom ui_latih import Ui_latih# 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)
        #call text
        self.isiDataFile(filename)
    def isiDataFile(self, nmfile):
        #open with read mode
        teksFile = open(nmfile, 'r').read()
        self.ui.textFile.setText(teksFile)
    import xml.etree.ElementTree as ET
    tree = ET.parse(filename)
    doc = tree.getroot()
    for elem in doc.findall('Default_Config/gmd:denominator'):
        x = elem.tag, elem.text
        self.ui.lineSkala.setText(x)
    for elem in doc.findall('Default_Config/gmd:MD_Format'):
        y = elem.tag, elem.text
        self.ui.lineFitur.setText(y)
I try using Element Tree to parse and show ScaleValue in LineEdit because
its integrated in python, but i have error message like this :
NameError: name 'filename' is not defined
i am really newbie in python and xml parser, can i pass the xml location
from open xml code to
tree = ET.parse( )
because i plan to open more than one xml file and scale in one and another
xml file have different value as well
Can Someone help me?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20140324/3f090c03/attachment.html>
    
    
More information about the Qgis-user
mailing list