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