简体   繁体   中英

Performance issue in parssing XML file using android XmlPullParser

I'm writing a simple android application with only two Fragments. First is a list of content and second is a full data about that content. I want to store my data in an xml file formatet like below.

    <item1>
       <f1>data</f1>
       <f2>data</f2>
       <f3>data</f3>
       <f4>data</f4>
       <f5>data</f5>
    </item1>
    <item2>
    .....
    </item2>

I want to use f1, f2 and f3 for creating my custom list view and all the fields for whole data. I already accomplished that by using XmlPullParser that reads whole data and put is in ArrayList of represented java objects.

The Problem is I do not want the to process the whole data every time. My preferred way would be something like this

When creating list view

  1. only read f1, f2 and f3 from my file since i don't need f4 and f5.

  2. only read as few items as possible at first! Since only 5 - 10 items would show at screen i would like to pars them first and when i'm recycling the views pars the items as needed.

When displaying content

  • only get the item i want not the hundred others i don't care about!

So how can i accomplish this?! Can i read lets say 200th item of an xml file in efficient way? Thanks in advance for your answer.

Why don't you just work with a database? I think for storing over 200 records, it is recommended to use a database. Also, your xml is not valid. You need a root tag like this:

<items>
    <item1>
        <f1>data</f1>
        <f2>data</f2>
        <f3>data</f3>
        <f4>data</f4>
        <f5>data</f5>
    </item1>
    <item2>
        .....
    </item2>
</items>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM