Esempio n. 1
0
 def __init__(self,
              validate=0,
              keepAllWs=0,
              catName=None,
              saxHandlerClass=XmlDomGenerator,
              parser=None):
     self.parser = parser or (validate and
                              sax2exts.XMLValParserFactory.make_parser()
                              ) or sax2exts.XMLParserFactory.make_parser()
     if catName:
         #set up the catalog, if there is one
         from xml.parsers.xmlproc import catalog
         cat_handler = catalog.SAX_catalog(catName,
                                           catalog.CatParserFactory())
         self.parser.setEntityResolver(cat_handler)
     self.handler = saxHandlerClass(keepAllWs)
     self.parser.setContentHandler(self.handler)
     self.parser.setDTDHandler(self.handler)
     self.parser.setErrorHandler(self.handler)
     try:
         #FIXME: Maybe raise a warning?
         self.parser.setProperty(handler.property_lexical_handler,
                                 self.handler)
         self.parser.setProperty(handler.property_declaration_handler,
                                 self.handler)
     except (SystemExit, KeyboardInterrupt):
         raise
     except:
         pass
     return
Esempio n. 2
0
 def __init__(self, validate=0, keepAllWs=0, catName=None,
              saxHandlerClass=XmlDomGenerator, parser=None):
     #Create an XML DOM from SAX events
     self.parser = parser or (validate and saxexts.XMLValParserFactory.make_parser()) or saxexts.XMLParserFactory.make_parser()
     if catName:
         #set up the catalog, if there is one
         from xml.parsers.xmlproc import catalog
         cat_handler = catalog.SAX_catalog(catName, catalog.CatParserFactory())
         self.parser.setEntityResolver(cat_handler)
     self.handler = saxHandlerClass(keepAllWs)
     self.parser.setDocumentHandler(self.handler)
     self.parser.setDTDHandler(self.handler)
     self.parser.setErrorHandler(self.handler)
     return
Esempio n. 3
0
    from xml.parsers.xmlproc import namespace

    nsf = namespace.NamespaceFilter(p)
    nsf.set_application(app)
    p.set_application(nsf)
else:
    p.set_application(app)

if cat != None:
    pf = xcatalog.FancyParserFactory(err_lang)
elif cat == None and os.environ.has_key("XMLXCATALOG"):
    cat = os.environ["XMLXCATALOG"]
    pf = xcatalog.XCatParserFactory(err_lang)
elif cat == None and os.environ.has_key("XMLSOCATALOG"):
    cat = os.environ["XMLSOCATALOG"]
    pf = catalog.CatParserFactory(err_lang)

if cat != None:
    print "Parsing catalog file '%s'" % cat
    cat = catalog.xmlproc_catalog(cat, pf, err)
    p.set_pubid_resolver(cat)

if len(sysids) == 0:
    if cat == None:
        print_usage("You must specify a system identifier if no catalog is "
                    "used")
    elif cat.get_document_sysid() == None:
        print_usage("You must specify a system identifier if the catalog has "
                    "no DOCUMENT entry")

    sysids = [cat.get_document_sysid()]