从Xml.parse退出时发现匹配 [英] Exiting from Xml.parse when match is found

查看:133
本文介绍了从Xml.parse退出时发现匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了Android SAX解析器在一个相当大的(6MB)XML文件来搜索条目。我基本上使用清单8的此处。我的问题是我怎么停止解析一次,我发现匹配?显示的code继续通过文件的末尾解析,但我想在那之前停下来。这是可能的,或者我需要使用比SAX以外的东西(例如XmlPullParser?)

I'm using the Android SAX parser to search for entries in a rather large (6MB) XML file. I'm basically using a derivative of the code shown in listing 8 here. The question I have is how do I stop parsing once my match has been found? The code shown continues parsing through the end of the file but I want to stop before then. Is this possible or do I need to use something other than SAX (e.g. XmlPullParser?)

推荐答案

生成的ArithmeticException并抓住它!
如果(条件){int类型的= 1;一个/ = 0; }
...

Generate an ArithmeticException and catch it ! if (condition) { int a=1; a/=0; } ...

try {
    Xml.parse(this.getInputStream(), Xml.Encoding.UTF_8, root.getContentHandler());
} 
catch (ArithmeticException e) {
    return true;
}

这是可怕的,但它的工作原理...

That's awful but it works...

这篇关于从Xml.parse退出时发现匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆