On Wed, 14 Mar 2007 Sameer Niphadkar wrote :
On Wed, 14 Mar 2007 Nikhil Marathe wrote :
- How does one get the exact value of an element down a tree like say : <abc><xyz><pqr>100</pqr></xyz></abc>
So in the above case say the value 100, though it could be a >>string >>as well. We require the exact value, not its representation >>in XML or >>ASCII value as explained by you in some books.
You could get the node's value and pass it to python's eval >function. Since eval returns the parsed python expression it will >give a logical return value like 100 as an int and abcd as a string
Rigth now we are importing minidom lib and trying to parse it by element names like :
reflist = xmldoc.getElementsByTagName("pqr") #For the case above ref = reflist[0]
Just as u mentioned..the node value. So do we need to pass reflist[0] i.e the 1st child here to the eval function ? Also could you please elaborate on this function.
Actually this is what we were looking fwd to :
#This is also true of re.split:
splitter = re.compile('<.>')
splitter.split('hi<a>there<b>from<c>python')
['hi', 'there', 'from', 'python']
'You will be what you WILL to Be' -James Allen