org.xml.sax.Parser.setDocumentHandler()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中org.xml.sax.Parser.setDocumentHandler()方法的一些代码示例,展示了Parser.setDocumentHandler()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.setDocumentHandler()方法的具体详情如下:
包路径:org.xml.sax.Parser
类名称:Parser
方法名:setDocumentHandler

Parser.setDocumentHandler介绍

[英]Allow an application to register a document event handler.

If the application does not register a document handler, all document events reported by the SAX parser will be silently ignored (this is the default behaviour implemented by HandlerBase).

Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.
[中]允许应用程序注册文档事件处理程序。
如果应用程序没有注册文档处理程序,SAX解析器报告的所有文档事件都将被静默忽略(这是HandlerBase实现的默认行为)。
应用程序可以在解析过程中登记新的或不同的处理程序,SAX解析器必须立即使用新的处理程序。

代码示例

代码示例来源:origin: org.apache.ant/ant

  1. /**
  2. * Creates a handler and sets the parser to use it
  3. * for the current element.
  4. *
  5. * @param helperImpl the ProjectHelperImpl instance associated
  6. * with this handler.
  7. *
  8. * @param parentHandler The handler which should be restored to the
  9. * parser at the end of the element.
  10. * Must not be <code>null</code>.
  11. */
  12. public AbstractHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler) {
  13. this.parentHandler = parentHandler;
  14. this.helperImpl = helperImpl;
  15. // Start handling SAX events
  16. helperImpl.parser.setDocumentHandler(this);
  17. }

代码示例来源:origin: org.apache.ant/ant

  1. /**
  2. * Handles the end of an element. Any required clean-up is performed
  3. * by the finished() method and then the original handler is restored to
  4. * the parser.
  5. *
  6. * @param name The name of the element which is ending.
  7. * Will not be <code>null</code>.
  8. *
  9. * @exception SAXException in case of error (not thrown in
  10. * this implementation)
  11. */
  12. public void endElement(String name) throws SAXException {
  13. // Let parent resume handling SAX events
  14. helperImpl.parser.setDocumentHandler(parentHandler);
  15. }
  16. }

代码示例来源:origin: org.apache.ant/ant

  1. project.log("parsing buildfile " + bFile + " with URI = " + uri, Project.MSG_VERBOSE);
  2. HandlerBase hb = new RootHandler(this);
  3. parser.setDocumentHandler(hb);
  4. parser.setEntityResolver(hb);
  5. parser.setErrorHandler(hb);

代码示例来源:origin: robovm/robovm

  1. /**
  2. * Initialize the parser before each run.
  3. */
  4. private void setupParser ()
  5. {
  6. // catch an illegal "nonsense" state.
  7. if (!prefixes && !namespaces)
  8. throw new IllegalStateException ();
  9. nsSupport.reset();
  10. if (uris)
  11. nsSupport.setNamespaceDeclUris (true);
  12. if (entityResolver != null) {
  13. parser.setEntityResolver(entityResolver);
  14. }
  15. if (dtdHandler != null) {
  16. parser.setDTDHandler(dtdHandler);
  17. }
  18. if (errorHandler != null) {
  19. parser.setErrorHandler(errorHandler);
  20. }
  21. parser.setDocumentHandler(this);
  22. locator = null;
  23. }

代码示例来源:origin: robovm/robovm

  1. parser.setDocumentHandler(hb);
  2. parser.setEntityResolver(hb);
  3. parser.setErrorHandler(hb);

代码示例来源:origin: org.w3c.jigsaw/jigsaw

  1. XMLParser(InputStream in)
  2. throws IOException, SAXException
  3. {
  4. state = IN_NOTHING;
  5. value = new StringBuffer();
  6. try {
  7. parser = getParser();
  8. parser.setDocumentHandler(this);
  9. } catch (Exception e) {
  10. e.printStackTrace();
  11. throw new SAXException("can't create parser ");
  12. }
  13. parser.parse(new InputSource(in));
  14. }

代码示例来源:origin: org.w3c.jigsaw/jigsaw

  1. protected void parse()
  2. throws SAXException, IOException
  3. {
  4. parser.setDocumentHandler(this);
  5. parser.setErrorHandler(this);
  6. parser.parse(new InputSource(reader));
  7. }

代码示例来源:origin: org.netbeans.api/org-netbeans-swing-plaf

  1. private void parseTheme(){
  2. try{
  3. SAXParserFactory factory = SAXParserFactory.newInstance();
  4. factory.setValidating(false);
  5. factory.setNamespaceAware(false);
  6. Parser p = new XMLReaderAdapter(factory.newSAXParser().getXMLReader());
  7. p.setDocumentHandler(this);
  8. String externalForm = themeURL.toExternalForm();
  9. InputSource is = new InputSource(externalForm);
  10. p.parse(is);
  11. activeThemes=null; //dispose of now useless hashtable
  12. locator = null;
  13. }
  14. catch(java.io.IOException ie){
  15. System.err.println ("IO exception reading theme file"); //NOI18N
  16. } catch(org.xml.sax.SAXException se){
  17. System.err.println ("Error parsing theme file " + (locator != null ? "line " + locator.getLineNumber() : "")); //NOI18N
  18. } catch (ParserConfigurationException e) {
  19. System.err.println ("Couldn't create XML parser for theme file"); //NOI18N
  20. }
  21. }

代码示例来源:origin: org.w3c.jigsaw/jigsaw

  1. protected void parse()
  2. throws SAXException, IOException
  3. {
  4. try {
  5. parser.setDocumentHandler(this);
  6. parser.setErrorHandler(this);
  7. parser.parse(new InputSource(reader));
  8. } catch (IOException ex) {
  9. try { reader.close(); } catch (IOException ioex) {}
  10. throw ex;
  11. } catch (SAXException sex) {
  12. try { reader.close(); } catch (IOException ioex) {}
  13. throw sex;
  14. }
  15. }

代码示例来源:origin: org.w3c.jigsaw/jigsaw

  1. protected void parse()
  2. throws SAXException, IOException
  3. {
  4. try {
  5. parser.setDocumentHandler(this);
  6. parser.setErrorHandler(this);
  7. parser.parse(new InputSource(reader));
  8. // } catch (IOException ex) {
  9. // try { reader.close(); } catch (IOException ioex) {}
  10. // throw ex;
  11. // } catch (SAXException sex) {
  12. // try { reader.close(); } catch (IOException ioex) {}
  13. // throw sex;
  14. } finally {
  15. try { reader.close(); } catch (IOException ioex) {}
  16. }
  17. }

代码示例来源:origin: org.fudaa.business/fudaa-common-corba

  1. /**
  2. * Creates a new KOMLParser.
  3. * Use the system property org.xml.sax.parser to change the parser.
  4. *
  5. * @exception KOMLException Can't create a parser.
  6. */
  7. KOMLParser() throws KOMLException {
  8. try {
  9. parser = ParserFactory.makeParser();
  10. parser.setDocumentHandler(this);
  11. } catch (Exception e) {
  12. e.printStackTrace();
  13. throw new KOMLException("can't create SAX parser ");
  14. }
  15. buffer = new StringBuffer();
  16. byteBuffer = new ByteInputOutputStream(128);
  17. classes = new Hashtable();
  18. }

代码示例来源:origin: org.codehaus.castor/castor-xml

  1. protected void readSearchDescriptor(Parser parser, InputSource input)
  2. throws IOException, SAXException {
  3. SearchDescriptor desc;
  4. desc = new SearchDescriptor();
  5. parser.setDocumentHandler(desc);
  6. parser.parse(input);
  7. setSearchDescriptor(desc);
  8. }

代码示例来源:origin: org.codehaus.castor/castor-xml

  1. protected void readImportDescriptor(Parser parser, InputSource input)
  2. throws IOException, SAXException {
  3. ImportDescriptor desc;
  4. desc = new ImportDescriptor();
  5. parser.setDocumentHandler(desc);
  6. parser.parse(input);
  7. setImportDescriptor(desc);
  8. }

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

  1. protected void readImportDescriptor( Parser parser, InputSource input )
  2. throws IOException, SAXException
  3. {
  4. ImportDescriptor desc;
  5. desc = new ImportDescriptor();
  6. parser.setDocumentHandler( desc );
  7. parser.parse( input );
  8. setImportDescriptor( desc );
  9. }

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

  1. protected void readSearchDescriptor( Parser parser, InputSource input )
  2. throws IOException, SAXException
  3. {
  4. SearchDescriptor desc;
  5. desc = new SearchDescriptor();
  6. parser.setDocumentHandler( desc );
  7. parser.parse( input );
  8. setSearchDescriptor( desc );
  9. }

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide

  1. private Parser getParser(boolean validate) throws SAXException, ParserConfigurationException, FactoryConfigurationError {
  2. Parser parser;
  3. parser = new XMLReaderAdapter (XMLUtil.createXMLReader(validate));
  4. // create document handler and register it
  5. //parser.setEntityResolver(entityRes);
  6. parser.setEntityResolver(this);
  7. parser.setDocumentHandler(this);//before new InnerParser() - now this
  8. parser.setErrorHandler(this);
  9. return parser;
  10. }

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

  1. private Parser getParser(boolean validate) throws SAXException, ParserConfigurationException, FactoryConfigurationError {
  2. Parser parser;
  3. parser = new XMLReaderAdapter (XMLUtil.createXMLReader(validate));
  4. // create document handler and register it
  5. //parser.setEntityResolver(entityRes);
  6. parser.setEntityResolver(this);
  7. parser.setDocumentHandler(this);//before new InnerParser() - now this
  8. parser.setErrorHandler(this);
  9. return parser;
  10. }

代码示例来源:origin: org.codehaus.castor/castor-xml-schema

  1. protected void parseSchema(Parser parser, SchemaUnmarshaller schemaUnmarshaller, URILocation uri,
  2. String schemaLocation, String reason) throws SchemaException {
  3. Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
  4. parser.setDocumentHandler(handler);
  5. parser.setErrorHandler(handler);
  6. try {
  7. InputSource source = new InputSource(uri.getReader());
  8. source.setSystemId(uri.getAbsoluteURI());
  9. parser.parse(source);
  10. } catch (java.io.IOException ioe) {
  11. throw new SchemaException("Error reading " + reason + " file '" + schemaLocation + "'");
  12. } catch (org.xml.sax.SAXException sx) {
  13. throw new SchemaException(sx);
  14. }
  15. }

代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor

  1. public void importDocument( Parser parser, InputSource input )
  2. throws ImportExportException
  3. {
  4. Consumer consumer;
  5. consumer = createConsumer();
  6. parser.setDocumentHandler( consumer );
  7. try {
  8. parser.parse( input );
  9. } catch ( SAXException except ) {
  10. throw new ImportExportException( except );
  11. } catch ( IOException except ) {
  12. throw new ImportExportException( except );
  13. }
  14. if ( consumer.getResults() != null ) {
  15. importEntries( consumer.getResults() );
  16. }
  17. }

代码示例来源:origin: org.codehaus.castor/castor-xml

  1. public void importDocument(Parser parser, InputSource input) throws ImportExportException {
  2. Consumer consumer;
  3. consumer = createConsumer();
  4. parser.setDocumentHandler(consumer);
  5. try {
  6. parser.parse(input);
  7. } catch (SAXException except) {
  8. throw new ImportExportException(except);
  9. } catch (IOException except) {
  10. throw new ImportExportException(except);
  11. }
  12. if (consumer.getResults() != null) {
  13. importEntries(consumer.getResults());
  14. }
  15. }

相关文章