本文整理了Java中org.xml.sax.Parser.setDocumentHandler()
方法的一些代码示例,展示了Parser.setDocumentHandler()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.setDocumentHandler()
方法的具体详情如下:
包路径:org.xml.sax.Parser
类名称: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
/**
* 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);
}
代码示例来源: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: org.apache.ant/ant
project.log("parsing buildfile " + bFile + " with URI = " + uri, Project.MSG_VERBOSE);
HandlerBase hb = new RootHandler(this);
parser.setDocumentHandler(hb);
parser.setEntityResolver(hb);
parser.setErrorHandler(hb);
代码示例来源:origin: robovm/robovm
/**
* Initialize the parser before each run.
*/
private void setupParser ()
{
// catch an illegal "nonsense" state.
if (!prefixes && !namespaces)
throw new IllegalStateException ();
nsSupport.reset();
if (uris)
nsSupport.setNamespaceDeclUris (true);
if (entityResolver != null) {
parser.setEntityResolver(entityResolver);
}
if (dtdHandler != null) {
parser.setDTDHandler(dtdHandler);
}
if (errorHandler != null) {
parser.setErrorHandler(errorHandler);
}
parser.setDocumentHandler(this);
locator = null;
}
代码示例来源:origin: robovm/robovm
parser.setDocumentHandler(hb);
parser.setEntityResolver(hb);
parser.setErrorHandler(hb);
代码示例来源: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: org.w3c.jigsaw/jigsaw
protected void parse()
throws SAXException, IOException
{
parser.setDocumentHandler(this);
parser.setErrorHandler(this);
parser.parse(new InputSource(reader));
}
代码示例来源:origin: org.netbeans.api/org-netbeans-swing-plaf
private void parseTheme(){
try{
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(false);
Parser p = new XMLReaderAdapter(factory.newSAXParser().getXMLReader());
p.setDocumentHandler(this);
String externalForm = themeURL.toExternalForm();
InputSource is = new InputSource(externalForm);
p.parse(is);
activeThemes=null; //dispose of now useless hashtable
locator = null;
}
catch(java.io.IOException ie){
System.err.println ("IO exception reading theme file"); //NOI18N
} catch(org.xml.sax.SAXException se){
System.err.println ("Error parsing theme file " + (locator != null ? "line " + locator.getLineNumber() : "")); //NOI18N
} catch (ParserConfigurationException e) {
System.err.println ("Couldn't create XML parser for theme file"); //NOI18N
}
}
代码示例来源: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;
}
}
代码示例来源: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: org.fudaa.business/fudaa-common-corba
/**
* Creates a new KOMLParser.
* Use the system property org.xml.sax.parser to change the parser.
*
* @exception KOMLException Can't create a parser.
*/
KOMLParser() throws KOMLException {
try {
parser = ParserFactory.makeParser();
parser.setDocumentHandler(this);
} catch (Exception e) {
e.printStackTrace();
throw new KOMLException("can't create SAX parser ");
}
buffer = new StringBuffer();
byteBuffer = new ByteInputOutputStream(128);
classes = new Hashtable();
}
代码示例来源: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: org.codehaus.castor/castor-xml
protected void readImportDescriptor(Parser parser, InputSource input)
throws IOException, SAXException {
ImportDescriptor desc;
desc = new ImportDescriptor();
parser.setDocumentHandler(desc);
parser.parse(input);
setImportDescriptor(desc);
}
代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor
protected void readImportDescriptor( Parser parser, InputSource input )
throws IOException, SAXException
{
ImportDescriptor desc;
desc = new ImportDescriptor();
parser.setDocumentHandler( desc );
parser.parse( input );
setImportDescriptor( desc );
}
代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor
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
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: 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: org.codehaus.castor/castor-xml-schema
protected void parseSchema(Parser parser, SchemaUnmarshaller schemaUnmarshaller, URILocation uri,
String schemaLocation, String reason) throws SchemaException {
Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
parser.setDocumentHandler(handler);
parser.setErrorHandler(handler);
try {
InputSource source = new InputSource(uri.getReader());
source.setSystemId(uri.getAbsoluteURI());
parser.parse(source);
} catch (java.io.IOException ioe) {
throw new SchemaException("Error reading " + reason + " file '" + schemaLocation + "'");
} catch (org.xml.sax.SAXException sx) {
throw new SchemaException(sx);
}
}
代码示例来源:origin: org.codehaus.castor/com.springsource.org.castor
public void importDocument( Parser parser, InputSource input )
throws ImportExportException
{
Consumer consumer;
consumer = createConsumer();
parser.setDocumentHandler( consumer );
try {
parser.parse( input );
} catch ( SAXException except ) {
throw new ImportExportException( except );
} catch ( IOException except ) {
throw new ImportExportException( except );
}
if ( consumer.getResults() != null ) {
importEntries( consumer.getResults() );
}
}
代码示例来源:origin: org.codehaus.castor/castor-xml
public void importDocument(Parser parser, InputSource input) throws ImportExportException {
Consumer consumer;
consumer = createConsumer();
parser.setDocumentHandler(consumer);
try {
parser.parse(input);
} catch (SAXException except) {
throw new ImportExportException(except);
} catch (IOException except) {
throw new ImportExportException(except);
}
if (consumer.getResults() != null) {
importEntries(consumer.getResults());
}
}
内容来源于网络,如有侵权,请联系作者删除!