My Android application reads a huge XML file using Simple XML . Obviously, this takes some time. The fact is that at the moment I just need to get one list of items. Is there a way to make Simple XML not read all other elements?
I do not want to use another library. I'm just wondering if such advanced material is possible using Simple XML.
Thanks for the help.
EDIT
Using the MH clause , parsing still takes 50 seconds ...
So, I would like to try another solution from Ilya Bloch using XmlPullParser .
Here is the necessary 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>
:
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Animals {
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);
}
}
XmlPullParser? ...