如何从android中的HTTPResponse解析xml数据 [英] how to parse xml data from HTTPResponse in android
问题描述
我在android中进行了一项活动,因为我已经使用HttpPost进行了多部分实体请求,现在我也可以成功地重新放置repose.但是我不知道如何从response中获取那些数据.解析xml的链接,但是没有运气.请为此提供帮助.如何从xml respose中获取数据.我的代码如下:
i have made an activity in android,in that i have made a multipart entity request using HttpPost,Now i am getting successfull respose also.but thing is i dont know how to get those data from response.i have tried number of links for parsing xml but with no luck.Please help me for this.how to get data from my xml respose.My code is as below:
登录
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Consts.API_HOST + "/login");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
2);
nameValuePairs.add(new BasicNameValuePair("apiKey",
"JU7Jqt6X"));
nameValuePairs.add(new BasicNameValuePair("type", "xml"));
nameValuePairs.add(new BasicNameValuePair("email",
"yogesh@amarinfotech.com"));
nameValuePairs.add(new BasicNameValuePair("pwd", "123"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// xml response..!jigar...
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httppost,
responseHandler);
// end of res jigar...
System.out
.println("::::::::::::::::::::::::;;MY RESPONSE IN LOGIN ATIVITY::::::::::"
+ responseBody);
// making doc
Document doc = null;
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
StringReader sr = new StringReader(responseBody);
InputSource is = new InputSource(sr);
doc = builder.parse(is);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
} catch (Exception e) {
System.out
.println("::::::::::::::::::::::::::::MY exception in edit::::::::::::::::"
+ e.getMessage());
return null;
}
return null;
// Parsing Procedure......
回复
<?xml version="1.0" encoding="ISO-8859-1" ?>
<root>
<id>
8
</id>
<personal_title>
Mr.
</personal_title>
<first_name>
a
</first_name>
<middle_name>
b
</middle_name>
<last_name>
c
</last_name>
<email>
yogesh@amarinfotech.com
</email>
<password>
202cb962ac59075b964b07152d234b70
</password>
<mobile_number>
1234567890
</mobile_number>
<p_first_name>
</p_first_name>
<p_last_name>
</p_last_name>
<p_card_type>
</p_card_type>
<p_card_number>
</p_card_number>
<p_sec_code>
</p_sec_code>
<p_exp_month>
</p_exp_month>
<p_exp_year>
</p_exp_year>
<user_activation_key>
14164668001
</user_activation_key>
<varification>
1
</varification>
<send_mail>
0
</send_mail>
<status>
0
</status>
<register_date>
2014-11-20 23:04:14
</register_date>
<last_visit_date>
2014-11-20 23:04:14
</last_visit_date>
</root>
推荐答案
我通过我的方式得到了答案.大家都很高兴,但是我的问题得到了解决,实际上,所有人都在告诉我有关不同解析的信息,但是我想知道有关HTTP RESPONSE的解析的信息,所以我有我的解决方案,这里是: http://www.java2s.com/Code/Android/Development/getCharacterDataFromElement.htm
I got my answer by my way.Hello all for your responses but i got myy question solved by my way ,Actually all are telling me about different parsing but i want to know about the parsing from HTTP RESPONSE,So i have got my solution,here it is: http://www.java2s.com/Code/Android/Development/getCharacterDataFromElement.htm
感谢这篇有用的帖子.
这篇关于如何从android中的HTTPResponse解析xml数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!