[kwlug-disc] BASH compare items in two files
Raul Suarez
rarsa at yahoo.com
Fri Nov 5 15:32:32 EDT 2010
And here is the full Python sample code
===================================
#!/usr/bin/python"
from xml.sax import make_parser
from xml.sax.handler import ContentHandler
class NodeCountHandler(ContentHandler):
def __init__ (self):
self.nodesDict = {}
#just replace the next line with the actual loading of ids
self.setOfIDs = (1,2,3,4,5,6)
def startElement(self, name, attrs):
if not self.nodesDict.has_key(name) :
self.nodesDict[name] = 0
id = int(attrs.get('id',""))
print name, "\n"
print id, "\n"
if id in self.setOfIDs :
self.nodesDict[name] += 1
parser = make_parser()
curHandler = NodeCountHandler()
parser.setContentHandler(curHandler)
parser.parse(open('inputFile.xml'))
print curHandler.nodesDict
==================================
Raul Suarez
Technology consultant
Software, Hardware and Practices
_________________
Twitter: rarsamx
http://rarsa.blogspot.com/
An eclectic collection of random thoughts
More information about the kwlug-disc
mailing list