在解析Android中的大型XML文件时出现问题
是否有任何有效的XML解析器可供Android高效解析大型XML文件? XML文档在没有CDATA的元素中包含HTML文本。
目前我在Android中使用SAX解析器。 当字符串以HTML字符分隔时,我会追加字符串,但解析整个文件需要4-5分钟。 一旦我开始分析模拟器正在中止。 日志猫o / p如下所示...
我目前的情况:
我的查询是:
01-20 12:44:22.133:I / dalvikvm(19715):DALVIK螺纹:
01-20 12:44:22.143:I / dalvikvm(19715):“main”prio = 5 tid = 1 TIMED_WAIT
01-20 12:44:22.143:I / dalvikvm(19715):| group =“main”sCount = 1 dsCount = 0 s = N obj = 0x4001d8e0 self = 0xccb0
01-20 12:44:22.143:I / dalvikvm(19715):| sysTid = 19715 nice = 0 sched = 0/0 cgrp =默认句柄= -1345026008
01-20 12:44:22.143:I / dalvikvm(19715):| schedstat =(1890827936 745978586 1231)
01-20 12:44:22.143:I / dalvikvm(19715):在java.lang.Object.wait(Native Method)
01-20 12:44:22.143:I / dalvikvm(19715): - 等待<0x44e7c158>(一个android.os.MessageQueue)
01-20 12:44:22.143:I / dalvikvm(19715):在java.lang.Object.wait(Object.java:326)
01-20 12:44:22.143:I / dalvikvm(19715):at android.os.MessageQueue.next(MessageQueue.java:142)
01-20 12:44:22.143:I / dalvikvm(19715):在android.os.Looper.loop(Looper.java:110)
01-20 12:44:22.143:I / dalvikvm(19715):at android.app.ActivityThread.main(ActivityThread.java:4627)
01-20 12:44:22.143:I / dalvikvm(19715):在java.lang.reflect.Method.invokeNative(Native Method)
01-20 12:44:22.152:I / dalvikvm(19715):在java.lang.reflect.Method.invoke(Method.java:521)
01-20 12:44:22.152:I / dalvikvm(19715):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
01-20 12:44:22.152:I / dalvikvm(19715):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-20 12:44:22.152:I / dalvikvm(19715):at dalvik.system.NativeStart.main(Native Method)
01-20 12:44:22.152:I / dalvikvm(19715):“AsyncTask#1”prio = 5 tid = 7 RUNNABLE
01-20 12:44:22.152:I / dalvikvm(19715):| group =“main”sCount = 0 dsCount = 0 s = N obj = 0x44e98170 self = 0x116238
01-20 12:44:22.152:I / dalvikvm(19715):| sysTid = 19721 nice = 0 sched = 0/0 cgrp =默认句柄= 1139576
01-20 12:44:22.162:I / dalvikvm(19715):| schedstat =(30192250334 11754013998 4287)
01-20 12:44:22.162:I / dalvikvm(19715):在java.lang.AbstractStringBuilder。(AbstractStringBuilder.java:~89)
01-20 12:44:22.162:I / dalvikvm(19715):在java.lang.StringBuilder。(StringBuilder.java:96)
01-20 12:44:22.162:I / dalvikvm(19715):at com.app.sampleApp.ExampleHandler.characters(ExampleHandler.java:346)
01-20 12:44:22.162:I / dalvikvm(19715):at org.apache.harmony.xml.ExpatParser.text(ExpatParser.java:167)
01-20 12:44:22.162:I / dalvikvm(19715):at org.apache.harmony.xml.ExpatParser.append(Native Method)
01-20 12:44:22.162:I / dalvikvm(19715):at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:521)
01-20 12:44:22.162:I / dalvikvm(19715):at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:482)
01-20 12:44:22.162:I / dalvikvm(19715):at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:320)
01-20 12:44:22.162:I / dalvikvm(19715):at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:277)
01-20 12:44:22.162:I / dalvikvm(19715):at com.app.sampleApp.SplashScreen.parsing(SplashScreen.java:95)
01-20 12:44:22.162:I / dalvikvm(19715):at com.app.sampleApp.SplashScreen $ FetchDataFromServer.doInBackground(SplashScreen.java:66)
01-20 12:44:22.162:I / dalvikvm(19715):at com.app.sampleApp.SplashScreen $ FetchDataFromServer.doInBackground(SplashScreen.java:1)
01-20 12:44:22.173:我/ dalvikvm(19715):在android.os.AsyncTask $ 2.call(AsyncTask.java:185)
01-20 12:44:22.173:I / dalvikvm(19715):在java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:305)
01-20 12:44:22.173:I / dalvikvm(19715):在java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-20 12:44:22.173:I / dalvikvm(19715):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
01-20 12:44:22.173:I / dalvikvm(19715):在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:561)
01-20 12:44:22.173:I / dalvikvm(19715):在java.lang.Thread.run(Thread.java:1096)
01-20 12:44:22.173:I / dalvikvm(19715):“Binder Thread#2”prio = 5 tid = 6 NATIVE
01-20 12:44:22.173:I / dalvikvm(19715):| group =“main”sCount = 1 dsCount = 0 s = N obj = 0x44e7adc0 self = 0x136b18
01-20 12:44:22.173:I / dalvikvm(19715):| sysTid = 19720 nice = 0 sched = 0/0 cgrp =默认句柄= 1277072
01-20 12:44:22.173:I / dalvikvm(19715):| schedstat =(4379710 8487993 4)
01-20 12:44:22.173:I / dalvikvm(19715):at dalvik.system.NativeStart.run(Native Method)
01-20 12:44:22.183:I / dalvikvm(19715):“Binder Thread#1”prio = 5 tid = 5 NATIVE
01-20 12:44:22.183:I / dalvikvm(19715):| group =“main”sCount = 1 dsCount = 0 s = N obj = 0x44e77130 self = 0x132868
01-20 12:44:22.183:I / dalvikvm(19715):| sysTid = 19719 nice = 0 sched = 0/0 cgrp =默认句柄= 1271608
01-20 12:44:22.183:I / dalvikvm(19715):| schedstat =(9087362 4814877 5)
01-20 12:44:22.183:I / dalvikvm(19715):at dalvik.system.NativeStart.run(Native Method)
01-20 12:44:22.183:I / dalvikvm(19715):“JDWP”守护进程prio = 5 tid = 4 VMWAIT
01-20 12:44:22.183:I / dalvikvm(19715):| group =“system”sCount = 1 dsCount = 0 s = N obj = 0x44e752a0 self = 0x1245a0
01-20 12:44:22.183:I / dalvikvm(19715):| sysTid = 19718 nice = 0 sched = 0/0 cgrp =默认句柄= 1178336
01-20 12:44:22.183:I / dalvikvm(19715):| schedstat =(13148782 23404684 16)
01-20 12:44:22.183:I / dalvikvm(19715):at dalvik.system.NativeStart.run(Native Method)
01-20 12:44:22.183:I / dalvikvm(19715):“Signal Catcher”daemon prio = 5 tid = 3 VMWAIT
01-20 12:44:22.183:I / dalvikvm(19715):| group =“system”sCount = 1 dsCount = 0 s = N obj = 0x44e751e8 self = 0x120298
01-20 12:44:22.183:I / dalvikvm(19715):| sysTid = 19717 nice = 0 sched = 0/0 cgrp =默认句柄= 1275872
01-20 12:44:22.192:I / dalvikvm(19715):| schedstat =(650295 9179530 2)
01-20 12:44:22.192:I / dalvikvm(19715):at dalvik.system.NativeStart.run(Native Method)
01-20 12:44:22.192:I / dalvikvm(19715):“HeapWorker”守护进程prio = 5 tid = 2 VMWAIT
01-20 12:44:22.192:I / dalvikvm(19715):| group =“system”sCount = 1 dsCount = 0 s = N obj = 0x438b8d00 self = 0x12efc0
01-20 12:44:22.192:I / dalvikvm(19715):| sysTid = 19716 nice = 0 sched = 0/0 cgrp =默认句柄= 1249312
01-20 12:44:22.192:I / dalvikvm(19715):| schedstat =(92741950 1647777523 865)
01-20 12:44:22.192:I / dalvikvm(19715):at com.android.internal.os.BinderInternal $ GcWatcher.finalize(BinderInternal.java:~48)
01-20 12:44:22.192:I / dalvikvm(19715):at dalvik.system.NativeStart.run(Native Method)
对于大型XML使用DOM解析器
您可能想要尝试XmlPullParser这是一个非验证解析器。 它在简单的XML结构上运行得非常好,并允许更高性能的分析器。
在文档中有一些示例代码可用
在普通的Java-land中,XML Pull Parser通常是最快的。 它看起来像在Andriod上可用。
链接地址: http://www.djcxy.com/p/61977.html