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
I replied a while ago, but the message was rejected as being too big. So here it goes shortened:
It seems you are new to Python. Try invoking the help function in the interactive interpreter. FOr help about eval (or any other methods, functions, classes, modules) do help(eval)
I am not that familiar with minidom but you can always copy all the >nodes attributes and children and remove the node and add another. >You should check the python library reference for the > xml.dom.minidompackage.
Thnx, yes we are going thru the mindom, but is there a method available in this case ?
As I said I am not very familiar with the minidom. go to python.org and see the library reference for the minidom You can also do help(minidom) after importing minidom. You may want to check out the book Dive Into Python (free, diveintopython.org ) which extensively covers both DOM and SAX parsing. I have also written a library to interface with Flickr sometime ago. You might want to check out the XML parsing their ( http://22bits.exofire.net/browse.php/code/flipper) . The file to check out is the xmlparser.py or similar.
Np, but we just need to bind our script with QT, so I guess we may only need
PyQT..am I right ? Thnks a lot for all the pointers though. rgds
Yes you only need pyqt. Most likely ur distro repos will have it. PyQt has most of the structure same as Qt. Their are slight differences in running the QApplication instance(notably using app.exec_loop ()). A quick google search for PyQt tutorials should get you started no problem. http://www.commandprompt.com/community/pyqt/ is a book on PyQt by Krita contributor Rempt. http://www.diotavelli.net/PyQtWiki/DocsAndHowtos is the PyQt Wiki's documentation list. It is better to refer to trolltech's original Qt docs for the class reference since help() is not of much help (no pun intended) when the functions use the SIP layer
And I have go a suggestion and a feature request. Suggestion -> Try to keep the 'library' seperate so that you just need to write seperate GUI and command line clients. So effectively your basic library should not need Qt. Also make sure your gui client uses multithreading(python supports it well and easy) to avoid freezing the interface. Feature Request -> As you live in India you know how pathetic net speeds here are. So it would be really cool if your pkg management system could be such that when a user upgrades a package only the files which have changed since the previous versions would be downloaded instead of the whole new package(diff and patch perhaps? or their python equivalents)
PS. If you need more help maybe we can live chat. see http://22bits.exofire.net/browse.php/about . I am no pro ( just got into 12th) but I will try my best.