在Android中解析大型xml文件的问题

时间:2011-12-28 11:46:44

标签: android xml xml-parsing

Android是否有高效的XML解析器可以有效地解析大型XML文件。 XML文档在没有CDATA的元素中包含HTML文本。

目前我在Android中使用SAX Parser。我在HTML字符中断时会附加字符串,但解析整个文件需要4-5分钟。一旦我开始解析模拟器正在中止。 Log cat o / p如下所示......

我目前的情况:

  1. SD卡上的11 MB XML文件
  2. 文件包含XML中某些元素的HTML文本,并未包含在CDATA中
  3. 模拟器在2-3分钟后中止
  4. 我的疑问是:

    1. Android中有解决大文件的实际限制吗
    2. 我应该使用对这些文件更有效的其他解析器
    3.   

      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):|基团="主" 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):at 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):at java.lang.Object.wait(Object.java:326)
        01-20 12:44:22.143:I / dalvikvm(19715):在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):在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):|基团="主" 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):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):在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):|基团="主" 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):|基团="主" 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):|基团="系统" 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"守护进程prio = 5 tid = 3 VMWAIT
        01-20 12:44:22.183:I / dalvikvm(19715):|基团="系统" 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):|基团="系统" 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)

3 个答案:

答案 0 :(得分:1)

对于大XML使用 DOM Parser

答案 1 :(得分:0)

您可能想尝试XmlPullParser这是一个非验证解析器。它在简单的XML结构上运行良好,并允许更高性能的解析器。

文档中有一些example code

答案 2 :(得分:0)

在常规Java领域,XML Pull Parser通常是最快的。它似乎可以在Andriod上使用。