本文整理汇总了Java中org.xml.sax.XMLReader.setDTDHandler方法的典型用法代码示例。如果您正苦于以下问题:Java XMLReader.setDTDHandler方法的具体用法?Java XMLReader.setDTDHandler怎么用?Java XMLReader.setDTDHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.xml.sax.XMLReader
的用法示例。
在下文中一共展示了XMLReader.setDTDHandler方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
public static void load(ThemeNULL theme, InputStream in) throws IOException {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setValidating(true);
try {
SAXParser parser = spf.newSAXParser();
XMLReader reader = parser.getXMLReader();
XmlHandler handler = new XmlHandler();
handler.theme = theme;
reader.setEntityResolver(handler);
reader.setContentHandler(handler);
reader.setDTDHandler(handler);
reader.setErrorHandler(handler);
InputSource is = new InputSource(in);
is.setEncoding("UTF-8");
reader.parse(is);
} catch (/*SAX|ParserConfiguration*/Exception se) {
se.printStackTrace();
throw new IOException(se.toString());
}
}
示例2: parse
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
* Parse the content given {@link org.xml.sax.InputSource}
* as XML using the specified
* {@link org.xml.sax.helpers.DefaultHandler}.
*
* @param is The InputSource containing the content to be parsed.
* @param dh The SAX DefaultHandler 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, DefaultHandler dh)
throws SAXException, IOException {
if (is == null) {
throw new IllegalArgumentException("InputSource cannot be null");
}
XMLReader reader = this.getXMLReader();
if (dh != null) {
reader.setContentHandler(dh);
reader.setEntityResolver(dh);
reader.setErrorHandler(dh);
reader.setDTDHandler(dh);
}
reader.parse(is);
}
示例3: dtdhandler01
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
* No exception expected when set DTD handler as simple DTD handler.
*
* @throws Exception If any errors occur.
*/
@Test
public void dtdhandler01() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
XMLReader xmlReader = spf.newSAXParser().getXMLReader();
XMLFilterImpl xmlFilter = new XMLFilterImpl();
xmlReader.setDTDHandler(xmlFilter);
assertEquals(xmlReader.getDTDHandler(), xmlFilter);
}
示例4: test
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
XMLReader reader = spf.newSAXParser().getXMLReader();
reader.setErrorHandler(null); // SAX 2.0.1 allows
reader.setContentHandler(null); // SAX 2.0.1 allows
reader.setEntityResolver(null); // SAX 2.0.1 allows
reader.setDTDHandler(null); // SAX 2.0.1 allows
}
示例5: createFromXMLReader
import org.xml.sax.XMLReader; //导入方法依赖的package包/类
/**
* Create contents of a buffer from a {@link XMLReader} and {@link InputStream}.
*
* <p>
* The MutableXMLStreamBuffer is reset (see {@link #reset}) before creation.
*
* <p>
* The MutableXMLStreamBuffer is created by using an instance of {@link SAXBufferCreator}
* and registering associated handlers on the {@link XMLReader}.
*
* @param reader
* The {@link XMLReader} to use for parsing.
* @param in
* The {@link InputStream} to be parsed.
* @param systemId
* The system ID of the input stream.
*/
public void createFromXMLReader(XMLReader reader, InputStream in, String systemId) throws SAXException, IOException {
reset();
SAXBufferCreator c = new SAXBufferCreator(this);
reader.setContentHandler(c);
reader.setDTDHandler(c);
reader.setProperty(Properties.LEXICAL_HANDLER_PROPERTY, c);
c.create(reader, in, systemId);
}