title: Sending a xml file to a web service in android
body: <p>Hello Friends I am trying to send an xml file stored in my sd card through my android app with the piece of code below:</p>
  
  <pre><code>    public class CartDetailsActivity extends Activity {
      File newxmlfile = new File(Environment.getExternalStorageDirectory() + "/"+GlobalVariables.ada_login+".xml");
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.cart_details);
  
          Button payButton=(Button)findViewById(R.id.pay);
          payButton.setOnClickListener(new OnClickListener() 
          {
  
              @Override
              public void onClick(View arg0) {
                  // TODO Auto-generated method stub
                  new PostXmlClass().execute();
              }
  
  
  
  
  
      });
  }
  
      public class PostXmlClass extends AsyncTask&lt;Void, Void, Void&gt; {
  
          private final ProgressDialog dialog = new ProgressDialog(
          CartDetailsActivity.this);
  
  protected void onPreExecute() {
      this.dialog.setMessage("Loading...");
      this.dialog.setCancelable(false);
      this.dialog.show();
  }
      @Override
      protected Void doInBackground(Void... params) {
  
          String url = "http://mywebsite.com/myfolder/mypage.php";
  
          try {
              HttpClient httpclient = new DefaultHttpClient();
  
              HttpPost httppost = new HttpPost(url);
  
              InputStreamEntity reqEntity = new InputStreamEntity(
                      new FileInputStream(newxmlfile), -1);
              reqEntity.setContentType("binary/octet-stream");
              reqEntity.setChunked(true); // Send in multiple parts if needed
              httppost.setEntity(reqEntity);
              HttpResponse response = httpclient.execute(httppost);
              //Do something with response...
  
          } catch (Exception e) {
              // show error
          } // inside the method paste your file uploading code
          return null;
      }
  
      protected void onPostExecute(Void result) {
  
          // Here if you wish to do future process for ex. move to another activity do here
  
          if (dialog.isShowing()) {
              dialog.dismiss();
          }
  
      }
  }
  }
  </code></pre>
  
  <p>xml file is of the type:</p>
  
  <pre><code>&lt;?xml version='1.0' standalone='yes' ?&gt;
  &lt;root&gt;
    &lt;item&gt;
      &lt;code&gt;ACT358&lt;/code&gt;
      &lt;price&gt;110.00&lt;/price&gt;
      &lt;quantity&gt;3&lt;/quantity&gt;
      &lt;totalcost&gt;330.0&lt;/totalcost&gt;
    &lt;/item&gt;
  
  &lt;item&gt;
    &lt;code&gt;ACT443&lt;/code&gt;
    &lt;price&gt;110.00&lt;/price&gt;
    &lt;quantity&gt;2&lt;/quantity&gt;
    &lt;totalcost&gt;220.0&lt;/totalcost&gt;
  &lt;/item&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I don't know whats wrong with this code as it is not working and file does not get uploaded. Any help will be appreciated. </p>