Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>craete your xml file based on this example</p> <pre><code>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); </code></pre> <p>and write the content into xml file</p> <pre><code>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); </code></pre> <p>post your file by</p> <pre><code>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); </code></pre> <p>methode getFileContent is</p> <pre><code>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(); } </code></pre> <p><a href="http://xjaphx.wordpress.com/2011/10/27/android-xml-adventure-create-write-xml-data/">reference</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload