[Qgis-user] QGIS Plugin to open and parse xml metadata

2014-03-24 Thread Suryo Miles
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:denominatorgco:IntegerScaleValue/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?
___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user

Re: [Qgis-user] QGIS Plugin to open and parse xml metadata

2014-03-24 Thread Horst Düster
substitute filename with self.filename than it should work


All the best
Horst Düster


Am 24.03.2014 17:45, schrieb Suryo Miles:
 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:denominatorgco:IntegerScaleValue/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?



 ___
 Qgis-user mailing list
 Qgis-user@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/qgis-user

-- 

--
Dr. Horst Düster
Managing Director
Sourcepole AG - Linux  Open Source Solutions 
Weberstrasse 5, 8004 Zürich, Switzerland
Tel: +41 (0)44 440 77 11
Direkt: +41 (0)44 515 67 70
horst.dues...@sourcepole.ch  http://www.sourcepole.ch

www.sourcepole.ch/kurse - Das Kursangebot Frühjahr 2014

___
Qgis-user mailing list
Qgis-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user