class BonsaiParser: def __init__(self, bonsaiURL): self.dom = minidom.parse(urlopen(bonsaiURL)) nodes = self.dom.getElementsByTagName("ci") if nodes.length < 1: return self.currentCiNode = nodes[0] self.currentFileNode = self.firstFileNode() def hasData(self): if self.currentCiNode: return True else: return False def nextCiNode(self): self.currentCiNode = self.currentCiNode.nextSibling if self.currentCiNode: return True else: return False def getLog(self): log = "" for child in self.currentCiNode.childNodes: if child.nodeType == Node.ELEMENT_NODE and child.tagName == "log": log = child.firstChild.data return log def firstFileNode(self): for child in self.currentCiNode.childNodes: if child.nodeType == Node.ELEMENT_NODE and child.tagName == "files": for c in child.childNodes: if c.nodeType == Node.ELEMENT_NODE and c.tagName == "f": return c def nextFileNode(self): # every other sibling is a , so go two past the current one try: self.currentFileNode = self.currentFileNode.nextSibling.nextSibling except AttributeError: self.currentFileNode = None if self.currentFileNode: return True else: return False def hasFile(self): if self.currentFileNode: return True else: return False def getFile(self): return self.currentFileNode.firstChild.data