我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用xml.sax.handler.ErrorHandler()。
def create_parser(target, store): parser = make_parser() try: # Workaround for bug in expatreader.py. Needed when # expatreader is trying to guess a prefix. parser.start_namespace_decl( "xml", "http://www.w3.org/XML/1998/namespace") except AttributeError: pass # Not present in Jython (at least) parser.setFeature(handler.feature_namespaces, 1) rdfxml = RDFXMLHandler(store) rdfxml.setDocumentLocator(target) # rdfxml.setDocumentLocator(_Locator(self.url, self.parser)) parser.setContentHandler(rdfxml) parser.setErrorHandler(ErrorHandler()) return parser
def xml_parse(filename, path=()): if sys.version_info[0:2] == (2,3): # XXX: this is for older versions of python source = "file://%s" % os.path.abspath(filename) else: source = filename h = parsers.XMLParser() p = xml.sax.make_parser() p.setContentHandler(h) p.setErrorHandler(ErrorHandler()) p.setEntityResolver(Resolver(path)) p.parse(source) return h.parser.tree
def xml_parse(filename, path=()): source = "file://%s" % os.path.abspath(filename) h = parsers.XMLParser() p = xml.sax.make_parser() p.setContentHandler(h) p.setErrorHandler(ErrorHandler()) p.setEntityResolver(Resolver(path)) p.parse(source) return h.parser.tree
def create_parser(store): parser = make_parser() try: # Workaround for bug in expatreader.py. Needed when # expatreader is trying to guess a prefix. parser.start_namespace_decl( "xml", "http://www.w3.org/XML/1998/namespace") except AttributeError: pass # Not present in Jython (at least) parser.setFeature(handler.feature_namespaces, 1) trix = TriXHandler(store) parser.setContentHandler(trix) parser.setErrorHandler(ErrorHandler()) return parser