Android - Parsear XML desde webservice

 
Vista:
sin imagen de perfil
Val: 1
Ha disminuido su posición en 26 puestos en Android (en relación al último mes)
Gráfica de Android

Parsear XML desde webservice

Publicado por Alejandro (1 intervención) el 03/12/2017 00:02:18
Hola, tengo una duda sobre como parsear el contenido que recibo en un xml desde http://www.webservicex.net/Geoipservice.asmx?op=GetGeoIP

tengo el codigo donde recibo el xml, pero no se como parsearlo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public static String httpPostRequest(Context context, String ip) {
	String response = "";
	BufferedReader reader = null;
	HttpURLConnection conn = null;
	String data ="";
	try {
 
		URL urlObj = new URL("http://www.webservicex.net/geoipservice.asmx/GetGeoIP");
 
		conn = (HttpURLConnection) urlObj.openConnection();
		conn.setRequestMethod("POST");
		conn.setDoOutput(true);
		OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
 
		data += "&" + URLEncoder.encode("IPAddress", "UTF-8") + "="
				+ URLEncoder.encode(ip, "UTF-8");
 
 
		wr.write(data);
		wr.flush();
 
		int responseCode = conn.getResponseCode();
 
		reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		StringBuilder sb = new StringBuilder();
		String line = null;
 
		while ((line = reader.readLine()) != null) {
			sb.append(line + "\n");
		}
 
		response = sb.toString();
	} catch (Exception e) {
		e.printStackTrace();
 
	} finally {
		try {
			reader.close();
			if (conn != null) {
				conn.disconnect();
			}
		} catch (Exception ex) {
		}
	}
 
	return response;
}

debo poner el contenido de ese xml en un documento y guardarlo en la memoria interna?. Gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder