Issue with parsing big xml files in Android

Are there any efficient XML parsers for Android to parse large XML files efficiently. The XML document has HTML text inside an element without CDATA.

Currently I am using SAX Parser in Android. I am appending the Strings when it breaks at HTML characters, but it takes up to 4-5 minutes to parse the entire file. Once I start parsing the emulator is aborting. Log cat o/p is shown as below...

My current scenario:

  • 11 MB XML file on the SD card
  • File contains HTML text for some elements in XML and it is not enclosed in CDATA
  • Emulator aborting after 2-3 minutes
  • My queries are:

  • Are there any practical limitations in Android to parse large files
  • Should I use a different parser which is more efficient for such files
  • 01-20 12:44:22.133: I/dalvikvm(19715): DALVIK THREADS:
    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=default handle=-1345026008
    01-20 12:44:22.143: I/dalvikvm(19715): | schedstat=( 1890827936 745978586 1231 )
    01-20 12:44:22.143: I/dalvikvm(19715): at java.lang.Object.wait(Native Method)
    01-20 12:44:22.143: I/dalvikvm(19715): - waiting on <0x44e7c158> (a android.os.MessageQueue)
    01-20 12:44:22.143: I/dalvikvm(19715): at 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): at 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): at java.lang.reflect.Method.invokeNative(Native Method)
    01-20 12:44:22.152: I/dalvikvm(19715): at 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=default handle=1139576
    01-20 12:44:22.162: I/dalvikvm(19715): | schedstat=( 30192250334 11754013998 4287 )
    01-20 12:44:22.162: I/dalvikvm(19715): at java.lang.AbstractStringBuilder.(AbstractStringBuilder.java:~89)
    01-20 12:44:22.162: I/dalvikvm(19715): at 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: I/dalvikvm(19715): at android.os.AsyncTask$2.call(AsyncTask.java:185)
    01-20 12:44:22.173: I/dalvikvm(19715): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    01-20 12:44:22.173: I/dalvikvm(19715): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    01-20 12:44:22.173: I/dalvikvm(19715): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
    01-20 12:44:22.173: I/dalvikvm(19715): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
    01-20 12:44:22.173: I/dalvikvm(19715): at 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=default handle=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=default handle=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" daemon 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=default handle=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=default handle=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" daemon 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=default handle=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解析器


    You may want to try the XmlPullParser which is a non-validating parser. It works very well on simple XML structures and allows for higher performance parsers.

    There's some example code available in the documentation


    In regular Java-land, the XML Pull Parser is usually the fastest. And it looks like it's available on Andriod.

    链接地址: http://www.djcxy.com/p/61978.html

    上一篇: ANR意向广播

    下一篇: 在解析Android中的大型XML文件时出现问题