I am doing a php webserver that have communication with android phone. And android phone mainly collect location information and send to webserver while location is updated.
the code below is studied online and i cannot understand them well.
I AM NOT SURE HOW TO READ THE XML FORMAT DATA IN PHP.
most of the example use Parser and SimpleXML, but they mostly know the xml file name, however my code seems no naming of the xml file. And i don't know how to do.
code that connect the php webservice, generate xml file and send.
private String postLocation(double lat, double lng){
HttpPost httpPost = new HttpPost(url);
try {
StringBuilder sb = new StringBuilder();
sb.append("<Location>");
sb.append("<lat>");
sb.append(lat);
sb.append("</lat>");
sb.append("<lng>");
sb.append(lng);
sb.append("</lng>");
sb.append("</Location>");
StringEntity entity = new StringEntity(sb.toString(), "UTF-8");
httpPost.setEntity(entity);
httpPost.addHeader("Accept", "application/xml");
httpPost.addHeader("Content-Type", "application/xml");
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse =
(HttpResponse) httpclient.execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
String strResult = EntityUtils.toString(httpResponse
.getEntity());
//return entity.toString();
return strResult;
}
catch(exception.........){}
}