Why is data from an XML file not retrieving in PHP?

silentknight

New Member
This is an HTTP client in Android that sends an XML file to a PHP server. I am getting a null pointer exception when making an \[code\]if\[/code\] check on http response.\[code\]public void httpinsert(final File file) throws Exception { InetAddress intt=InetAddress.getLocalHost(); String adress=intt.getHostAddress(); System.out.println("IP ASSRESSS"+adress); if (isNetworkAvailable()==true) { System.out.println("<>>><><><><><><><><><><>"+ file.getAbsolutePath()); //HttpParams httpParameters = new BasicHttpParams(); //HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1); //HttpConnectionParams.setConnectionTimeout(httpParameters, 60000); //HttpConnectionParams.setSoTimeout(httpParameters, 60000); //HttpConnectionParams.setTcpNoDelay(httpParameters, true); HttpClient htp = new DefaultHttpClient(); HttpPost hp = new HttpPost("http://192.168.1.109/txt.php"); FileEntity fe = new FileEntity(file, HTTP.UTF_8); fe.setContentType("text/xml"); hp.setEntity(fe); HttpResponse hrespone = htp.execute(hp); HttpEntity hentity = hrespone.getEntity(); String httpresponse=EntityUtils.toString(hentity); System.out.println("RESPONSE"+httpresponse); if (httpresponse!=null) { DBAdapter dba=new DBAdapter(mycontext); try { dba.updatefetched(); } catch (Exception e) { e.printStackTrace(); } } } else { try { Toast.makeText(null, "Network is not avaiable try again", Toast.LENGTH_LONG).show(); this.wait(60000); this.httpinsert(file); } catch (InterruptedException e) { e.printStackTrace(); } }}\[/code\]I am getting an HTTP response like this when I print it on the screen:\[code\]RESPONSE</br></br></br></br></br></br></br></br></br></br></br></br>\[/code\]My PHP server code for parsing the XML file is this:\[code\]<?php $mysongs = simplexml_load_file('data.xml'); foreach($mysongs as $studentinfo): $regno=$studentinfo->regno; $name=$studentinfo->name; $fname=$studentinfo->fname; $city=$studentinfo->city; $age=$studentinfo->age; $action=$studentinfo->action; if ($action=="Insert") { echo "</br>"; echo "Data is to be inserted"; echo "</br>"; } if ($action=="delete") { echo "</br>"; echo "Data is to be Deleted"; echo "</br>"; } if ($action=="Update") { echo "</br>"; echo "Data is to be Updated"; echo "</br>"; } echo $regno; echo "</br>"; echo $name; echo "</br>"; echo $fname; echo "</br>"; echo $city; echo "</br>"; echo $age; echo "</br>"; echo $action; echo "</br>"; endforeach;?>\[/code\]My XML file is:\[code\] <?xml version='1.0' encoding='UTF-8' standalone='yes' ?> <Students> <student> <regno>5</regno> <name>ali</name> <fname>kjjjjj</fname> <age>87</age> <city>jkkjkjkjk</city> <action>Insert</action> </student> </Students>\[/code\]How can I retrieve all this XML data through PHP code and insert it into a database? What is the error in my PHP code or Android code?
 
Back
Top