Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fetches data from local Android xml folder having xml file and returns in Arraylist
public ArrayList<string> prepareListFromXml() {
ArrayList<string> todoItems = new ArrayList<string>();
XmlResourceParser todolistXml = getResources().getXml(R.xml.todolist);
int eventType = -1;
while (eventType != XmlResourceParser.END_DOCUMENT) {
if (eventType == XmlResourceParser.START_TAG) {
String strNode = todolistXml.getName();
if (strNode.equals("item")) {
todoItems.add(todolistXml.getAttributeValue(null, "title"));
}
}
try {
eventType = todolistXml.next();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return todoItems;
}
<!--?xml version="1.0" encoding="utf-8"?-->
<todoitems>
<item title="Going to Gym" description="">
<item title="Get ready for office" description="">
<item title="Lunch with friends" description="">
<item title="Going to movie" description="">
</item></item></item></item></todoitems>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment