[LDTP-Dev] LDTP - Data XML Parser code !!!

Nagappan A anagappan at novell.com
Mon Sep 26 04:27:15 PDT 2005


Hi,
    Added XML Data parser code in ldtputils.py.

Thanks
Nagappan

http://gnomebangalore.org/ldtp/index.php/Data_XML_File_Parser


Index: ldtputils.py
===================================================================
RCS file: /cvs/pyldtp/ldtputils.py,v
retrieving revision 1.23
diff -u -p -r1.23 ldtputils.py
--- ldtputils.py        26 Sep 2005 18:56:20 -0000      1.23
+++ ldtputils.py        26 Sep 2005 18:57:58 -0000
@@ -210,3 +210,47 @@ def closeappwindow (window_name):
 def wait (seconds):
        time.sleep (seconds)

+# XML Data file parser
+class LdtpDataFileParser:
+       def __init__ (self, filename = None):
+               self.ldtpdataxml = []
+               if filename != None:
+                       try:
+                               dom = xml.dom.minidom.parse (filename)
+                               self.ldtpdataxml = 
dom.getElementsByTagName ("data")
+                               if self.ldtpdataxml == []:
+                                       ldtp.log ('data xml tag not 
present')
+                                       print 'data xml tag not present'
+                       except xml.parsers.expat.ExpatError, msg:
+                               ldtp.log ('XML Error: ' + str (msg), 
'error')
+                       except IOError:
+                               ldtp.log ('XML \"' + filename + '\" file 
not found', 'error')
+       def setfilename (self, filename):
+               self.ldtpdataxml = []
+               if filename != None:
+                       try:
+                               dom = xml.dom.minidom.parse (filename)
+                               self.ldtpdataxml = 
dom.getElementsByTagName ("data")
+                               if self.ldtpdataxml == []:
+                                       ldtp.log ('data xml tag not 
present')
+                                       print 'data xml tag not present'
+                       except xml.parsers.expat.ExpatError, msg:
+                               print 'XML Error: ' + str (msg)
+                               ldtp.log ('XML Error: ' + str (msg), 
'error')
+                       except IOError:
+                               print 'XML \"' + filename + '\" file not 
found'
+                               ldtp.log ('XML \"' + filename + '\" file 
not found', 'error')
+       def getText (self, nodelist):
+               rc = ""
+               for node in nodelist:
+                       if node.nodeType == node.TEXT_NODE:
+                               rc = rc + node.data
+               return rc
+       def gettagvalue (self, tagname):
+               self.taglist = []
+               if self.ldtpdataxml == []:
+                       return self.taglist
+               for dataelements in self.ldtpdataxml:
+                       for data in dataelements.getElementsByTagName 
(tagname):
+                               self.taglist.append (self.getText 
(data.childNodes))
+               return self.taglist

-- 
Nagappan A <anagappan at novell.com>
Novell Software Development (I) Pvt. Ltd.
Linux Desktop Testing Project - http://gnomebangalore.org/ldtp/index.php/Main_Page
http://nagappanal.blogspot.com/



More information about the Ldtp-dev mailing list