爪哇.萨克斯解析器.如何手动中断解析? [英] Java. Sax parser. How to manually break parsing?
本文介绍了爪哇.萨克斯解析器.如何手动中断解析?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请告诉我是否可以中断解析过程?IE.退出这个循环没有到达文档的结尾和相应的事件endDocument"?
Tell me please is it possible to break the process of parsing? I.e. exit this loop not reaching the end of document and corresponding event "endDocument" ?
推荐答案
在处理程序中抛出异常并在您开始解析的代码块中捕获它:
Throw an exception in the handler and catch it in the code block where you started parsing:
try {
...
xmlReader.parse();
} catch (SAXException e) {
if (e.Cause instanceof BreakParsingException) {
// we have broken the parsing process
....
}
}
在你的 DocumentHandler 中:
And in your DocumentHandler:
public void startElement(String namespaceURI,
String localName,
String qName,
Attributes atts)
throws SAXException {
// ...
throw new SAXException(new BreakParsingException());
}
这篇关于爪哇.萨克斯解析器.如何手动中断解析?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文