I am creating a simple app in which I have an xml file with about 70,000 lines. The xml file looks like this:
<!--<?xml version="1.0" encoding="utf-8"?>-->
<!--<resources></resources>-->
<Root>
<Item ItemNumber="OXB433"/>
<Item ItemNumber="JMQ14P"/>
<Item ItemNumber="A882E2"/>
<Item ItemNumber="LLMH3K"/>
<Item ItemNumber="BEM3QD"/>
<Item ItemNumber="XKMM6R"/>
*** about 70,000 of these lines ***
</Root>
And this is how I am trying to parse the xml and store it in an ArrayList of strings.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
String item = getItemFromXML(this);
} catch (XmlPullParserException e) {
} catch (IOException e) {
}
final String[] items = item.split("\n");
}
public String getItemFromXML(Activity activity) throws XmlPullParserException, IOException{
StringBuffer stringBuffer = new StringBuffer();
Resources res = activity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.items);
xpp.next();
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT){
if (eventType == XmlPullParser.START_TAG){
if (xpp.getName().equals("Item")){
stringBuffer.append(xpp.getAttributeValue(null, "ItemNumber") + "\n");
}
}
eventType = xpp.next();
}
return stringBuffer.toString();
}
Now here is the problem, when I click "run", gradle build takes about 3 minutes to build and after troubleshooting and debugging, I found out that it takes so long because of 70,000 lines in my xml file. When I reduced my xml file to 10 lines, gradle build finished in 8 seconds. So how do I solve this problem? I can't reduce the xml file and I can't wait 3 minutes for gradle to build.
Note: my file "items.xml" is inside an folder named "xml" which is under "res" folder.
Thank you :)