--- nfo/projects/netfraggle/bin/fraggleParserXML.py 2004/08/25 13:53:48 1.1 +++ nfo/projects/netfraggle/bin/fraggleParserXML.py 2004/08/26 23:10:12 1.4 @@ -1,32 +1,53 @@ #fraggleParserXML: Class for parsing XML from a stream or file import sys +import fraggleError + from xml.dom.ext.reader import Sax2 -from xml.marshal import generic +from xml.marshal import * def create(parent): - return fraggleParserXML() + return fraggleParserXML(parent) class fraggleParserXML: - def __init_reader__(): - reader = Sax2.Reader() - marshall = generic.Marshaller() + def __init_reader__(self): + self.reader = Sax2.Reader() + def __init__(self,parent): self.__init_reader__() - def parseXML(input): - dom = self.reader.fromStream(input) + def parseXML(self,input): + try: + dom = self.reader.fromStream(input) + except: + fraggleError.errorXMLStreamNotValid() return dom - def printXML(inputDom,outputLocation): - file = open(outputLocation,"w") - self.reader.PrettyPrint(inputDom,file) + def printXML(self,inputDom,outputLocation): + try: + file = open(outputLocation,"w") + self.reader.PrettyPrint(inputDom,file) + except: + fraggleError.errorFileNotFound(outputLocation) + + def marshalXML(self,values,outputLocation): + try: + file = open(outputLocation,"w") + # self.marshall.dump(values,file) + generic.dump(values,file) + except: + fraggleError.errorFileNotFound(outputLocation) - def marshalXML(value,outputLocation): - file = open(outputLocation,"w") - marshall.dump(value,file) - - \ No newline at end of file + + #print generic.dumps(values) + + def unmarshalXML(self,inputLocation): + try: + file = open(inputLocation,"r") + except: + fraggleError.errorFileNotFound(inputLocation) + return generic.load(file) + \ No newline at end of file