craete your xml file based on this example
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// root elements
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("Order");
doc.appendChild(rootElement);
//set attribute to class
Attr Rattr = doc.createAttribute("Order_atrribute");
Rattr.setValue(curtrade);
rootElement.setAttributeNode(Rattr);
// companyid elements
Element staff = doc.createElement("companyid");
rootElement.appendChild(staff);
// shorten way
// staff.setAttribute("id", "1");
// firstname elements
Element firstname = doc.createElement("orderitems");
firstname.appendChild(doc.createTextNode("hii"));
staff.appendChild(firstname);
and write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File(this.getFilesDir().getAbsolutePath(),"file.xml"));
//String s=this.getFilesDir().getAbsolutePath();
// Output to console for testing
//StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
post your file by
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url_context + "/orders/order.php");
String filePath = this.getFilesDir().getAbsolutePath();
File f=new File(filePath,"file.xml");
//byte[] data = FileOperator.readBytesFromFile(f);
String content=getFileContents(f);
StringEntity se = new StringEntity( content, HTTP.UTF_8);
se.setContentType("text/xml");
httppost.setEntity(se);
f.delete();
HttpResponse httpresponse = httpClient.execute(httppost);
Log.d("xml1", httpresponse.toString());
HttpEntity resEntity = httpresponse.getEntity();
Log.d("xml2", resEntity.toString());
String result1 = EntityUtils.toString(resEntity);
Log.d("xml", "writer = "+result1);
methode getFileContent is
public String getFileContent(final File file) throws IOException {
final InputStream inputStream = new FileInputStream(file);
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
final StringBuilder stringBuilder = new StringBuilder();
boolean done = false;
while (!done) {
final String line = reader.readLine();
done = (line == null);
if (line != null) {
stringBuilder.append(line);
}
}
reader.close();
inputStream.close();
return stringBuilder.toString();
}
reference