Return an object after parsing xml with SAX

Posted by sentimental_turtle on Stack Overflow See other posts from Stack Overflow or by sentimental_turtle
Published on 2010-06-08T21:14:12Z Indexed on 2010/06/08 22:12 UTC
Read the original article Hit count: 219

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about python

Related posts about Xml