PDA

View Full Version : Reading and showing XML



targinosilveira
04-11-2011, 01:47 PM
Hi people, I would like to if somebody here knows a good tutorial to a programer coming from another language to programing for Android? I need to read a XML from a URL list records from XML and show details of each record...

But I don't know how to do it for Android, somebody can help me ? :D

Regards,

Targino Silveira

AllTime
04-12-2011, 07:55 AM
Hello Targino Silveira,

For your task, rather than knowing Android knowing Java is important. As you will be coding in Java only for the task you are looking for.

Android supports java.net, apache and other thrid party utilities also. But apache & java is enough. If you have to do POST to the URL, then you got to write code with respect to POST, if GET then with GET.

For GET, the below code reads a line of response. If you have more lines, you can store them to StringBuffer and append each read lien to the buffer. With this you will get the response in String form and you can parse your xml that is stored in String.


HttpClient client = new DefaultHttpClient();

//Prepare request object
HttpGet httpGet = new HttpGet(url);
HttpResponse response = null;
InputStream is = null;

response = client.execute(httpGet);
is = response.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
ip = br.readLine().trim();


Hope this helps.