Create a base class for xmlpullparser utility in android

dcgdifgdflgic

New Member
i have some problem with parsing XML using xmlpullparser API for androidProblem: i have a lot of duplication in android classes like Activity or some business class for xml parser but its a same!!! ..Required: some base class or util for xmlpullparser to make all parsing in the same class just i need send to him the URL for XML or for the WebService and i get the values and some utils if there is!.This what i have in the classes:\[code\] int count = 0; try { srv = new URL( "URL Web Service"); factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(false); xpp = factory.newPullParser(); xpp.setInput(XMLUtility.getInputStream(srv), "UTF_8"); insideItem = false; int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (xpp.getName().equalsIgnoreCase(tag)) { insideItem = true; } else if (xpp.getName().equalsIgnoreCase(SId)) { if (insideItem) id.add(xpp.nextText()); // extract the headline } else if (xpp.getName().equalsIgnoreCase(SEn)) { if (insideItem) enable.add(xpp.nextText()); } } else if (eventType == XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase(tag)) { insideItem = false; checkEnable.add(id.get(count) + "," + enable.get(count)); count++; } eventType = xpp.next(); } } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); }\[/code\]this code is duplicated just change the tag :( , Any ideas?
 
Back
Top