本文整理汇总了Java中org.xml.sax.Parser.setDocumentHandler方法的典型用法代码示例。如果您正苦于以下问题:Java Parser.setDocumentHandler方法的具体用法?Java Parser.setDocumentHandler怎么用?Java Parser.setDocumentHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xml.sax.Parser
的用法示例。
在下文中一共展示了Parser.setDocumentHandler方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseTheme
import org.xml.sax.Parser; //导入方法依赖的package包/类
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
}
}
示例2: parse
import org.xml.sax.Parser; //导入方法依赖的package包/类
private synchronized AnnotationType parse() {
if (annotationType == null) {
AnnotationType at = new AnnotationType();
Handler h = new Handler(at);
try {
Parser xp;
SAXParserFactory factory = SAXParserFactory.newInstance ();
factory.setValidating (false);
factory.setNamespaceAware(false);
xp = factory.newSAXParser ().getParser ();
xp.setEntityResolver(h);
xp.setDocumentHandler(h);
xp.setErrorHandler(h);
xp.parse(new InputSource(xmlDataObject.getInputStream()));
at.putProp(AnnotationType.PROP_FILE, xmlDataObject);
annotationType = at;
} catch (Exception e) {
LOG.warning("Corrupted xmlDataObject " + xmlDataObject.getPath());
Exceptions.printStackTrace(e);
}
}
return annotationType;
}
示例3: parse
import org.xml.sax.Parser; //导入方法依赖的package包/类
/**
* Parse the specified input source, reporting SAX1 events to the
* given handler.
* Prefer the SAX2 version of this method, since the HandlerBase class is
* now deprecated.
* @param is the SAX input source
* @param hb the SAX1 handler
* @exception IllegalArgumentException if the input source is null
* @see #parse(org.xml.sax.InputSource,org.xml.sax.helpers.DefaultHandler)
*/
public void parse(InputSource is, HandlerBase hb)
throws SAXException, IOException
{
if (is == null)
{
throw new IllegalArgumentException("input source is null");
}
Parser parser = getParser();
parser.setDocumentHandler(hb);
parser.setDTDHandler(hb);
parser.setEntityResolver(hb);
parser.setErrorHandler(hb);
parser.parse(is);
}
示例4: parse
import org.xml.sax.Parser; //导入方法依赖的package包/类
/**
* Parse the specified input source, reporting SAX1 events to the
* given handler.
* Prefer the SAX2 version of this method, since the HandlerBase class is
* now deprecated.
* @param is the SAX input source
* @param hb the SAX1 handler
* @exception IllegalArgumentException if the input source is null
* @see #parse(org.xml.sax.InputSource,org.xml.sax.helpers.DefaultHandler)
*/
public void parse(InputSource is, HandlerBase hb)
throws SAXException, IOException
{
if (is == null)
{
throw new IllegalArgumentException("input source is null");
}
Parser parser = getParser();
parser.setDocumentHandler(hb);
parser.setDTDHandler(hb);
parser.setEntityResolver(hb);
parser.setErrorHandler(hb);
parser.parse(is);
}
示例5: parse
import org.xml.sax.Parser; //导入方法依赖的package包/类
/**
* Parse the content given {@link org.xml.sax.InputSource}
* as XML using the specified
* {@link org.xml.sax.HandlerBase}.
* <i> Use of the DefaultHandler version of this method is recommended as
* the HandlerBase class has been deprecated in SAX 2.0</i>
*
* @param is The InputSource containing the content to be parsed.
* @param hb The SAX HandlerBase to use.
*
* @throws IllegalArgumentException If the <code>InputSource</code> object
* is <code>null</code>.
* @throws IOException If any IO errors occur.
* @throws SAXException If any SAX errors occur during processing.
*
* @see org.xml.sax.DocumentHandler
*/
public void parse(InputSource is, HandlerBase hb)
throws SAXException, IOException {
if (is == null) {
throw new IllegalArgumentException("InputSource cannot be null");
}
Parser parser = this.getParser();
if (hb != null) {
parser.setDocumentHandler(hb);
parser.setEntityResolver(hb);
parser.setErrorHandler(hb);
parser.setDTDHandler(hb);
}
parser.parse(is);
}
示例6: loadSchemaSource
import org.xml.sax.Parser; //导入方法依赖的package包/类
private void loadSchemaSource(InputSource source)
{
// -- get default parser from Configuration
Parser parser = null;
try {
parser = _config.getParser();
} catch (RuntimeException rte) {
// ignore
}
if (parser == null) {
// _dialog.notify("fatal error: unable to create SAX parser.");
return;
}
SchemaUnmarshaller schemaUnmarshaller = null;
try {
//schemaUnmarshaller = new SchemaUnmarshaller(new SchemaContextImpl());
schemaUnmarshaller = new SchemaUnmarshaller();
} catch (XMLException e) {
//--The default constructor cannot throw exception so this should never happen
//--just log the exception
e.printStackTrace();
System.exit(1);
}
Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
parser.setDocumentHandler(handler);
parser.setErrorHandler(handler);
try {
parser.parse(source);
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
} catch (org.xml.sax.SAXException sx) {
sx.printStackTrace();
return;
}
Schema schema = schemaUnmarshaller.getSchema();
try {
schema.validate();
} catch (ValidationException vx) {
new NestedIOException(vx).printStackTrace();
}
gmeSchema=schema;
}