1

I know that this is a duplicate Question. But i didn't get the proper answer. My question is that. I have some data and i want to convert that data into xml and i want to send this xml with HttpPost request. When This Post request is executed then it give me data in xml format. then i want to parse the xml data. Please tell me the best way to do it. I have read Some tutorial but I haven't get proper answer. is there no other way to convert object value into xml accounting to the class field Like marshaling and unmarshaling in java please tell me the answer. Thanks in advance. I have read some example here are some links. click here and here

Community
  • 1
  • 1
Umesh Kumar Saraswat
  • 728
  • 3
  • 10
  • 27
  • Have you checked this ? http://stackoverflow.com/questions/19586561/how-to-post-xml-data-to-server-in-android – Ganesh AB Dec 09 '14 at 05:35

1 Answers1

0

Simple example for XML parser using HTTP POST,

 HttpClient httpclient = new DefaultHttpClient();
 HttpPost httppost = new HttpPost("http://192.168.192.131/");

try {
StringEntity se = new StringEntity( "<aaaLogin inName=\"admin\" inPassword=\"admin123\"/>", HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setEntity(se);

HttpResponse httpresponse = httpclient.execute(httppost);
HttpEntity resEntity = httpresponse.getEntity();
tvData.setText(EntityUtils.toString(resEntity));        
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); 
}
Ranjithkumar
  • 14,780
  • 10
  • 107
  • 140
  • i have a doubt that if i need to add one more tag then i have to append that tag into "" ? is there no other way to convert object value into xml accounting to the class field Like marshaling and unmarshaling in java – Umesh Kumar Saraswat Dec 09 '14 at 05:59