Hi all,
I'm trying to read data from this xml file that looks like this:
<VEGETABLE >
< FRUIT >
<FRUIT name="apple">1</FRUIT>
<FRUIT name="Orange">2</FRUIT>
<FRUIT name="Benana">6</FRUIT>
I wrote the following script:
import sys
from xml.dom.minidom import parse
from cmath import sqrt
# Load XML into tree structure
tree = parse(sys.stdin)
#Find all <FRUITS>
pa_list=tree.getElementsByTagName('VEGETABLE')[0].getElementsByTagName('FRUITS')[0].getElementsByTagName('FRUITS')
#Find the 'T' node in the list of FRUITS
for pa in pa_list:
try:
if pa.attributes.getNamedItem('name').nodeValue == 'apple':
fru = pa
break
except:
pass
fruitvalue=0
fruitvalue=(float(fru.getElementsByTagName('apple').childNodes.data))
print "\t%g"% (fruitvalue)
I'm getting this error:
fruitvalue=(float(fru.getElementsByTagName('apple').childNodes.data))
NameError: name 'fru' is not defined
but I believable I'm defining it by: fru = pa.
Any help is extremely appreciated.