org.xml.sax.Parser类的使用及代码示例

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

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

Parser介绍

[英]Basic interface for SAX (Simple API for XML) parsers. This module, both source code and documentation, is in the Public Domain, and comes with NO WARRANTY. See http://www.saxproject.org for further information.

This was the main event supplier interface for SAX1; it has been replaced in SAX2 by org.xml.sax.XMLReader, which includes Namespace support and sophisticated configurability and extensibility.

All SAX1 parsers must implement this basic interface: it allows applications to register handlers for different types of events and to initiate a parse from a URI, or a character stream.

All SAX1 parsers must also implement a zero-argument constructor (though other constructors are also allowed).

SAX1 parsers are reusable but not re-entrant: the application may reuse a parser object (possibly with a different input source) once the first parse has completed successfully, but it may not invoke the parse() methods recursively within a parse.
[中]SAX(XML的简单API)解析器的基本接口*本模块包括源代码和文档,属于公共领域,不提供保修。*有关更多信息,请参见{$0$}。
这是SAX1的主要活动供应商界面;在SAX2中,它已被org取代。xml。萨克斯。XMLReader,包括名称空间支持、复杂的可配置性和可扩展性。
所有SAX1解析器都必须实现这个基本接口:它允许应用程序为不同类型的事件注册处理程序,并从URI或字符流启动解析。
所有SAX1解析器还必须实现零参数构造函数(尽管也允许使用其他构造函数)。
SAX1解析器是可重用的,但不是可重入的:一旦第一次解析成功完成,应用程序可以重用解析器对象(可能具有不同的输入源),但它可能不会在解析中递归调用parse()方法。

代码示例

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

  1. parser.setDocumentHandler(hb);
  2. parser.setEntityResolver(hb);
  3. parser.setErrorHandler(hb);
  4. parser.setDTDHandler(hb);
  5. parser.parse(is);

代码示例来源: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: uk.org.ponder.rsf/rsf-core-ponderutilcore

  1. private Object produceSubtreeInternal(Object rootobj, InputSource i) {
  2. parserstash.setDocumentHandler(this);
  3. parserstash.setEntityResolver(this);
  4. try {
  5. rootobjstash = rootobj;
  6. parserstash.parse(i); // begin to parse at this point, asynchronous events arrive
  7. }
  8. catch (SAXParseException spe) {
  9. throw UniversalRuntimeException.accumulate(spe, "SaxParseException occured at line "
  10. + spe.getLineNumber()
  11. + " column number "
  12. + spe.getColumnNumber());
  13. }
  14. catch (Exception e) {
  15. throw UniversalRuntimeException.accumulate(e, "Error parsing XML document");
  16. }
  17. finally {
  18. saxer.blastState();
  19. if (callback != null) {
  20. callback.parseComplete(callbackindex);
  21. callback = null;
  22. }
  23. }
  24. return rootobjstash;
  25. }

代码示例来源:origin: xml-resolver/xml-resolver

  1. /** Setup for parsing. */
  2. private void setupParse(String systemId) {
  3. allowXMLCatalogPI = true;
  4. parser.setEntityResolver(this);
  5. parser.setDocumentHandler(this);
  6. parser.setDTDHandler(this);
  7. URL cwd = null;
  8. try {
  9. cwd = FileURL.makeURL("basename");
  10. } catch (MalformedURLException mue) {
  11. cwd = null;
  12. }
  13. try {
  14. baseURL = new URL(systemId);
  15. } catch (MalformedURLException mue) {
  16. if (cwd != null) {
  17. try {
  18. baseURL = new URL(cwd, systemId);
  19. } catch (MalformedURLException mue2) {
  20. // give up
  21. baseURL = null;
  22. }
  23. } else {
  24. // give up
  25. baseURL = null;
  26. }
  27. }
  28. }

代码示例来源: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: robovm/robovm

  1. /**
  2. * Parse an XML document.
  3. *
  4. * @param input An input source for the document.
  5. * @exception java.io.IOException If there is a problem reading
  6. * the raw content of the document.
  7. * @exception SAXException If there is a problem
  8. * processing the document.
  9. * @see #parse(java.lang.String)
  10. * @see org.xml.sax.Parser#parse(org.xml.sax.InputSource)
  11. */
  12. public void parse (InputSource input)
  13. throws IOException, SAXException
  14. {
  15. if (parsing) {
  16. throw new SAXException("Parser is already in use");
  17. }
  18. setupParser();
  19. parsing = true;
  20. try {
  21. parser.parse(input);
  22. } finally {
  23. parsing = false;
  24. }
  25. parsing = false;
  26. }

代码示例来源: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: org.fudaa.business/fudaa-common-corba

  1. parser.setDocumentHandler(this);
  2. } catch (Exception e) {
  3. System.err.println("can't create parser <" + className +">");
  4. parser.setDocumentHandler(this);
  5. parser.setErrorHandler(this);

代码示例来源:origin: xml-resolver/xml-resolver

  1. /** SAX Parser API. */
  2. public void setErrorHandler(ErrorHandler handler) {
  3. parser.setErrorHandler(handler);
  4. }

代码示例来源: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: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders

  1. /** Factory SAX parser that can be used to parse XML files.
  2. * The factory is created according to javax.xml.parsers.SAXParserFactory property.
  3. * The parser has set entity resolver to system entity resolver chain.
  4. * @param validate if true validating parser is returned
  5. * @throws FactoryConfigurationError
  6. * @return sax parser or null if no parser can be created
  7. * @deprecated Use {@link XMLUtil#createXMLReader(boolean,boolean ) Util} instead
  8. * setting ns to false.
  9. * For more details see {@link #createParser() createParser}
  10. */
  11. public static Parser createParser (boolean validate) {
  12. Parser parser = XMLDataObjectImpl.makeParser(validate);
  13. parser.setEntityResolver(getChainingEntityResolver());
  14. return parser;
  15. }

代码示例来源:origin: xml-resolver/xml-resolver

  1. /** SAX Parser API. */
  2. public void setLocale(Locale locale) throws SAXException {
  3. parser.setLocale(locale);
  4. }

代码示例来源: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: xml-resolver/xml-resolver

  1. } else {
  2. Parser parser = (Parser) Class.forName(parserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
  3. parser.setDocumentHandler(this);
  4. if (bResolver != null) {
  5. parser.setEntityResolver(bResolver);
  6. parser.parse(new InputSource(is));

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.xmlresolver

  1. /** Setup for parsing. */
  2. private void setupParse(String systemId) {
  3. allowXMLCatalogPI = true;
  4. parser.setEntityResolver(this);
  5. parser.setDocumentHandler(this);
  6. parser.setDTDHandler(this);
  7. URL cwd = null;
  8. try {
  9. cwd = FileURL.makeURL("basename");
  10. } catch (MalformedURLException mue) {
  11. cwd = null;
  12. }
  13. try {
  14. baseURL = new URL(systemId);
  15. } catch (MalformedURLException mue) {
  16. if (cwd != null) {
  17. try {
  18. baseURL = new URL(cwd, systemId);
  19. } catch (MalformedURLException mue2) {
  20. // give up
  21. baseURL = null;
  22. }
  23. } else {
  24. // give up
  25. baseURL = null;
  26. }
  27. }
  28. }

代码示例来源: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: net.sf.squirrel-sql.thirdparty-non-maven/openide

  1. /** Starts parsing document, that can be localized by means of uri parameter
  2. * @param validate
  3. * @param uri adress of document, that will be parsed
  4. * @throws ParserConfigurationException
  5. * @throws IOException
  6. * @throws SAXException */
  7. public void parseXML(String uri, boolean validate) throws IOException, SAXException, ParserConfigurationException, FactoryConfigurationError {
  8. Parser parser = getParser(validate);
  9. parser.parse(uri);
  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: com.sun.xml.parsers/jaxp-ri

  1. /** SAX Parser API. */
  2. public void setErrorHandler(ErrorHandler handler) {
  3. parser.setErrorHandler(handler);
  4. }

代码示例来源: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. }

相关文章