Download XML instead of using a pre-stored one

Chrisworld2000

New Member
I'm trying to parse an XML file which is stored on a server.I followed the IBM tutorial for that and now I have the following activity:\[code\]public class ParsingXML extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.main); setContentView(R.layout.relativelayout); TextView journal = (TextView) findViewById(R.id.journal); TextView publisher = (TextView) findViewById(R.id.publisher); TextView edition1 = (TextView) findViewById(R.id.edition1); TextView title1 = (TextView) findViewById(R.id.title1); TextView author1 = (TextView) findViewById(R.id.author1); TextView edition2 = (TextView) findViewById(R.id.edition2); TextView title2 = (TextView) findViewById(R.id.title2); TextView author2 = (TextView) findViewById(R.id.author2); try { XmlResourceParser xpp = getResources().getXml(R.xml.catalog); xpp.next(); int eventType = xpp.getEventType(); int iter = 0; String elemtext = null; while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { String elemName = xpp.getName(); if (elemName.equals("catalog")) { String journalAttr = xpp.getAttributeValue(null, "journal"); String publisherAttr = xpp.getAttributeValue(null, "publisher"); journal.setText(journalAttr); publisher.setText(publisherAttr); } if (elemName.equals("article")) { iter = iter + 1; } if (elemName.equals("edition")) { elemtext = "edition"; } if (elemName.equals("title")) { elemtext = "title"; } if (elemName.equals("author")) { elemtext = "author"; } } else if (eventType == XmlPullParser.TEXT) { if (iter == 1) { if (elemtext.equals("edition")) { edition1.setText(xpp.getText()); } else if (elemtext.equals("title")) { title1.setText(xpp.getText()); } else if (elemtext.equals("author")) { author1.setText(xpp.getText()); } } else if (iter == 2) { if (elemtext.equals("edition")) { edition2.setText(xpp.getText()); } else if (elemtext.equals("title")) { title2.setText(xpp.getText()); } else if (elemtext.equals("author")) { author2.setText(xpp.getText()); } } } eventType = xpp.next(); } } catch (XmlPullParserException e) { } catch (IOException e) { }}\[/code\]The only problem is that the file is already stored in the res/xml folder instead of stored on a server. How do I implement the downloader?Please help!
 
Back
Top