Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7850013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:42:55+00:00 2026-06-02T18:42:55+00:00

My Android app reads a huge XML file using Simple XML . Obviously it

  • 0

My Android app reads a huge XML file using Simple XML. Obviously it takes a while. The fact is, at the moment, I just need to retrieve a single list of elements. Is there a way to force Simple XML not to read all other elements?

I do not want to use another library. I just wonder if this kind of advanced stuff is possible with Simple XML.

Thanks for the help.


EDIT

Using MH suggestion, the parsing still takes 50 sec…

So I would like to try the other solution from Ilya Blokh using XmlPullParser.

Here is the needed part of the XML file:

<?xml version="1.0" encoding="UTF-8"?>
<ROOT>
    ....
    <ANIMALS>
        <animal>
            <name>Dog</name>
            <color>white</color>
            <color>black</color>
            <color>brown</color>
        </animal>
        <animal>
            <name>Cat</name>
            <color>white</color>
            <color>black</color>
            <color>gray</color>
            <color>red</color>
        </animal>
        ...
    </ANIMALS>
    ...
</ROOT>

I would like to populate this class:

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Animals {

    /**
     * Key: animal name, Value: animal colors
     */
    private Map<String, List<String>> entries;

    public Animals() {
        entries = new HashMap<String, List<String>>();
    }

    public void addAnimal(String name, List<String> colors) {
        entries.put(name, colors);
    }

    public List<String> getColors(String animalName) {
        return entries.get(animalName);
    }
}

How could I deal with lists and XmlPullParser? I am not used to working with parsers…

Thanks again

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:42:56+00:00Added an answer on June 2, 2026 at 6:42 pm

    You can use the loose mapping flag to get around the strict requirement of specifying the whole document structure. This feature might be especially convenient in your case if you use it directly on the Persister, since you mention only being interested in a single list of elements. Have a look at and read through the example linked.

    Unfortunately I’m not familiar enough with the internals of Simple XML to say anything about “not to read all other elements”. I suppose the loose mapping option as described above will result in only the mapping you’re interested in, but I doubt you can avoid parsing the whole XML document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an Android app that's reads comments from an MS Power Point file.
I just tried to test my first android app using the emulator, it crashed
I need to develop an app that reads info from google calendar on Android.
I have a binary file I wish to read for my android app. the
My android app project need to add a new function of saving the click
Possible Duplicate: where to place an xml file with data in app I'm kinda
I'm writing an Android app that reads and parses NMEA sentences from GPS receiver
I have a simple app that reads internet resource and displays the information in
I am currently developing an app that reads out SMS/Emails while driving. Many users
I'm working on an android app that writes and reads .PNG files from sdcard.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.