Suppose I have an XML file in my assets with such data
<mods day="30" month="8" year="2012">
<mod id="1" name="1a">Hello123</mod>
<mod id="2" name="2a">Hello123</mod>
<mod id="3" name="3a">Hello123</mod>
</mods>
<mods day="31" month="8" year="2012">
<mod id="1" name="1a">Hello123</mod>
<mod id="2" name="2a">Hello123</mod>
<mod id="3" name="3a">Hello123</mod>
</mods>
and I need to find a certain “mod” parameter by inputting day, month, year and id.
here’s how far I got.
c.setTime(new Date());
String y = sdy.format(c.getTime());
String m = sdm.format(c.getTime());
String d = sdd.format(c.getTime());
InputStream istr = this.getAssets().open("mods.xml");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xrp;
xrp = factory.newPullParser();
xrp.setInput(istr, "UTF-8");
// not sure what to do next...
If I got it right, now I need to somehow query this xrp with my needed parameters, right?
Thanks!
Putting the XML as an XML resource in
res/xml/, not inassets/, it will parse 10x faster, courtesy of the optimizations in place for XML resources. Hence, I recommend using XML resources instead of XML in assets. You can see this CommonsWare sample project he uses the XMLPullParser to parse the xml resource.