Return an object after parsing xml with SAX
- by sentimental_turtle
I have some large XML files to parse and have created an object class to contain my relevant data. Unfortunately, I am unsure how to return the object for later processing. Right now I pickle my data and moments later depickle the object for access. This seems wasteful, and there surely must be a way of grabbing my data without hitting the disk.
def endElement(self, name):
if name == "info": # done collecting this iteration
self.data.setX(self.x)
self.data.setY(self.y)
elif name == "lastTagOfInterest": # done with file
# want to return my object from here
filehandler = open(self.outputname + ".pi", "w")
pickle.dump(self.data, filehandler)
filehandler.close()
I have tried putting a return statement in my endElement tag, but that does not seem to get passed up the chain to where I call the SAX parser.
Thanks for any tips.