<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
substitute filename with self.filename than it should work<br>
<br>
<br>
All the best<br>
Horst Düster<br>
<br>
<br>
<div class="moz-cite-prefix">Am 24.03.2014 17:45, schrieb Suryo
Miles:<br>
</div>
<blockquote
cite="mid:CAC0eZP823uuHOWTcFLkYGiBDPCDb8RQf7tGz9=g-QbS9zyAz-Q@mail.gmail.com"
type="cite">
<pre wrap="">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?
</pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Qgis-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/qgis-user">http://lists.osgeo.org/mailman/listinfo/qgis-user</a></pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
--
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
<a class="moz-txt-link-abbreviated" href="mailto:horst.duester@sourcepole.ch">horst.duester@sourcepole.ch</a> <a class="moz-txt-link-freetext" href="http://www.sourcepole.ch">http://www.sourcepole.ch</a>
<a class="moz-txt-link-abbreviated" href="http://www.sourcepole.ch/kurse">www.sourcepole.ch/kurse</a> - Das Kursangebot Frühjahr 2014</pre>
</body>
</html>