本文整理了Java中org.xml.sax.Parser
类的一些代码示例,展示了Parser
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser
类的具体详情如下:
包路径:org.xml.sax.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
parser.setDocumentHandler(hb);
parser.setEntityResolver(hb);
parser.setErrorHandler(hb);
parser.setDTDHandler(hb);
parser.parse(is);
代码示例来源:origin: org.w3c.jigsaw/jigsaw
protected void parse()
throws SAXException, IOException
{
parser.setDocumentHandler(this);
parser.setErrorHandler(this);
parser.parse(new InputSource(reader));
}
代码示例来源:origin: uk.org.ponder.rsf/rsf-core-ponderutilcore
private Object produceSubtreeInternal(Object rootobj, InputSource i) {
parserstash.setDocumentHandler(this);
parserstash.setEntityResolver(this);
try {
rootobjstash = rootobj;
parserstash.parse(i); // begin to parse at this point, asynchronous events arrive
}
catch (SAXParseException spe) {
throw UniversalRuntimeException.accumulate(spe, "SaxParseException occured at line "
+ spe.getLineNumber()
+ " column number "
+ spe.getColumnNumber());
}
catch (Exception e) {
throw UniversalRuntimeException.accumulate(e, "Error parsing XML document");
}
finally {
saxer.blastState();
if (callback != null) {
callback.parseComplete(callbackindex);
callback = null;
}
}
return rootobjstash;
}
代码示例来源:origin: xml-resolver/xml-resolver
/** Setup for parsing. */
private void setupParse(String systemId) {
allowXMLCatalogPI = true;
parser.setEntityResolver(this);
parser.setDocumentHandler(this);
parser.setDTDHandler(this);
URL cwd = null;
try {
cwd = FileURL.makeURL("basename");
} catch (MalformedURLException mue) {
cwd = null;
}
try {
baseURL = new URL(systemId);
} catch (MalformedURLException mue) {
if (cwd != null) {
try {
baseURL = new URL(cwd, systemId);
} catch (MalformedURLException mue2) {
// give up
baseURL = null;
}
} else {
// give up
baseURL = null;
}
}
}
代码示例来源:origin: org.w3c.jigsaw/jigsaw
XMLParser(InputStream in)
throws IOException, SAXException
{
state = IN_NOTHING;
value = new StringBuffer();
try {
parser = getParser();
parser.setDocumentHandler(this);
} catch (Exception e) {
e.printStackTrace();
throw new SAXException("can't create parser ");
}
parser.parse(new InputSource(in));
}
代码示例来源:origin: robovm/robovm
/**
* Parse an XML document.
*
* @param input An input source for the document.
* @exception java.io.IOException If there is a problem reading
* the raw content of the document.
* @exception SAXException If there is a problem
* processing the document.
* @see #parse(java.lang.String)
* @see org.xml.sax.Parser#parse(org.xml.sax.InputSource)
*/
public void parse (InputSource input)
throws IOException, SAXException
{
if (parsing) {
throw new SAXException("Parser is already in use");
}
setupParser();
parsing = true;
try {
parser.parse(input);
} finally {
parsing = false;
}
parsing = false;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
private Parser getParser(boolean validate) throws SAXException, ParserConfigurationException, FactoryConfigurationError {
Parser parser;
parser = new XMLReaderAdapter (XMLUtil.createXMLReader(validate));
// create document handler and register it
//parser.setEntityResolver(entityRes);
parser.setEntityResolver(this);
parser.setDocumentHandler(this);//before new InnerParser() - now this
parser.setErrorHandler(this);
return parser;
}
代码示例来源:origin: org.fudaa.business/fudaa-common-corba
parser.setDocumentHandler(this);
} catch (Exception e) {
System.err.println("can't create parser <" + className +">");
parser.setDocumentHandler(this);
parser.setErrorHandler(this);
代码示例来源:origin: xml-resolver/xml-resolver
/** SAX Parser API. */
public void setErrorHandler(ErrorHandler handler) {
parser.setErrorHandler(handler);
}
代码示例来源:origin: org.apache.ant/ant
/**
* Handles the end of an element. Any required clean-up is performed
* by the finished() method and then the original handler is restored to
* the parser.
*
* @param name The name of the element which is ending.
* Will not be <code>null</code>.
*
* @exception SAXException in case of error (not thrown in
* this implementation)
*/
public void endElement(String name) throws SAXException {
// Let parent resume handling SAX events
helperImpl.parser.setDocumentHandler(parentHandler);
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide-loaders
/** Factory SAX parser that can be used to parse XML files.
* The factory is created according to javax.xml.parsers.SAXParserFactory property.
* The parser has set entity resolver to system entity resolver chain.
* @param validate if true validating parser is returned
* @throws FactoryConfigurationError
* @return sax parser or null if no parser can be created
* @deprecated Use {@link XMLUtil#createXMLReader(boolean,boolean ) Util} instead
* setting ns to false.
* For more details see {@link #createParser() createParser}
*/
public static Parser createParser (boolean validate) {
Parser parser = XMLDataObjectImpl.makeParser(validate);
parser.setEntityResolver(getChainingEntityResolver());
return parser;
}
代码示例来源:origin: xml-resolver/xml-resolver
/** SAX Parser API. */
public void setLocale(Locale locale) throws SAXException {
parser.setLocale(locale);
}
代码示例来源:origin: org.w3c.jigsaw/jigsaw
protected void parse()
throws SAXException, IOException
{
try {
parser.setDocumentHandler(this);
parser.setErrorHandler(this);
parser.parse(new InputSource(reader));
// } catch (IOException ex) {
// try { reader.close(); } catch (IOException ioex) {}
// throw ex;
// } catch (SAXException sex) {
// try { reader.close(); } catch (IOException ioex) {}
// throw sex;
} finally {
try { reader.close(); } catch (IOException ioex) {}
}
}
代码示例来源:origin: xml-resolver/xml-resolver
} else {
Parser parser = (Parser) Class.forName(parserClass, true, loader != null ? loader : this.getClass().getClassLoader()).newInstance();
parser.setDocumentHandler(this);
if (bResolver != null) {
parser.setEntityResolver(bResolver);
parser.parse(new InputSource(is));
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.xmlresolver
/** Setup for parsing. */
private void setupParse(String systemId) {
allowXMLCatalogPI = true;
parser.setEntityResolver(this);
parser.setDocumentHandler(this);
parser.setDTDHandler(this);
URL cwd = null;
try {
cwd = FileURL.makeURL("basename");
} catch (MalformedURLException mue) {
cwd = null;
}
try {
baseURL = new URL(systemId);
} catch (MalformedURLException mue) {
if (cwd != null) {
try {
baseURL = new URL(cwd, systemId);
} catch (MalformedURLException mue2) {
// give up
baseURL = null;
}
} else {
// give up
baseURL = null;
}
}
}
代码示例来源:origin: org.codehaus.castor/castor-xml
protected void readSearchDescriptor(Parser parser, InputSource input)
throws IOException, SAXException {
SearchDescriptor desc;
desc = new SearchDescriptor();
parser.setDocumentHandler(desc);
parser.parse(input);
setSearchDescriptor(desc);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
/** Starts parsing document, that can be localized by means of uri parameter
* @param validate
* @param uri adress of document, that will be parsed
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException */
public void parseXML(String uri, boolean validate) throws IOException, SAXException, ParserConfigurationException, FactoryConfigurationError {
Parser parser = getParser(validate);
parser.parse(uri);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
private Parser getParser(boolean validate) throws SAXException, ParserConfigurationException, FactoryConfigurationError {
Parser parser;
parser = new XMLReaderAdapter (XMLUtil.createXMLReader(validate));
// create document handler and register it
//parser.setEntityResolver(entityRes);
parser.setEntityResolver(this);
parser.setDocumentHandler(this);//before new InnerParser() - now this
parser.setErrorHandler(this);
return parser;
}
代码示例来源:origin: com.sun.xml.parsers/jaxp-ri
/** SAX Parser API. */
public void setErrorHandler(ErrorHandler handler) {
parser.setErrorHandler(handler);
}
代码示例来源:origin: org.apache.ant/ant
/**
* Creates a handler and sets the parser to use it
* for the current element.
*
* @param helperImpl the ProjectHelperImpl instance associated
* with this handler.
*
* @param parentHandler The handler which should be restored to the
* parser at the end of the element.
* Must not be <code>null</code>.
*/
public AbstractHandler(ProjectHelperImpl helperImpl, DocumentHandler parentHandler) {
this.parentHandler = parentHandler;
this.helperImpl = helperImpl;
// Start handling SAX events
helperImpl.parser.setDocumentHandler(this);
}
内容来源于网络,如有侵权,请联系作者删除!