def __init__(self): saxlib.XMLReader.__init__(self) self.__parsing = 0 self.__validate = 0 self.__namespaces = 1 self.__locator = 0 self._lex_handler = saxlib.LexicalHandler() self._decl_handler = saxlib.DeclHandler()
def __init__(self): IncrementalParser.__init__(self) self.__parsing = 0 self.__validate = 0 self.__namespaces = 0 self.__ext_pes = 0 self.__locator = 0 self._lex_handler = saxlib.LexicalHandler() self._decl_handler = saxlib.DeclHandler() self._parser = None
def parse(self, source): try: self.__parsing = 1 # interpret source source = prepare_input_source(source) # create parser if self.__validate: parser = xmlval.XMLValidator() else: parser = xmlproc.XMLProcessor() # set handlers if self._cont_handler != None or self._lex_handler != None: if self._cont_handler == None: self._cont_handler = saxlib.ContentHandler() if self._lex_handler == None: self._lex_handler = saxlib.LexicalHandler() if self.__namespaces: filter = NamespaceFilter(parser, self._cont_handler, self._lex_handler, self) parser.set_application(filter) else: parser.set_application(self) if self._err_handler != None: parser.set_error_handler(self) if self._decl_handler != None or self._dtd_handler != None: parser.set_dtd_listener(self) # FIXME: set other handlers bufsize=16384 self._parser = parser # make it available for callbacks #parser.parse_resource(source.getSystemId()) # FIXME: rest! parser.set_sysid(source.getSystemId()) parser.read_from(source.getByteStream(), bufsize) source.getByteStream().close() parser.flush() parser.parseEnd() finally: self._parser = None self.__parsing = 0
def prepareParser(self, source): self.__parsing = 1 # create parser if self.__validate: parser = xmlval.XMLValidator() else: parser = xmlproc.XMLProcessor() # set handlers if self._cont_handler != None or self._lex_handler != None: if self._cont_handler == None: self._cont_handler = saxlib.ContentHandler() if self._lex_handler == None: self._lex_handler = saxlib.LexicalHandler() if self.__namespaces: filter = NamespaceFilter(parser, self._cont_handler, self._lex_handler, self) parser.set_application(filter) else: parser.set_application(self) if self._err_handler != None: parser.set_error_handler(self) if self._decl_handler != None or self._dtd_handler != None: parser.set_dtd_listener(self) parser.set_pubid_resolver(self) # FIXME: set other handlers if self.__ext_pes: parser.set_read_external_subset(1) self._parser = parser # make it available for callbacks if source: parser.set_sysid(source.getSystemId())