Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to write streamly xml file using serializer
    primarykey
    data
    text
    <p>hi i need to write xml file in android app which add longitude latitude and heart rate</p> <p>when i use it like this </p> <p>declare:<code>public XmlSerializer serializer = Xml.newSerializer();</code> init:</p> <pre><code>try { //we set the FileOutputStream as output for the serializer, using UTF-8 encoding serializer.setOutput(outputStream, "UTF-8"); //Write &lt;?xml declaration with encoding (if encoding not null) and standalone flag (if standalone not null) serializer.startDocument(null, Boolean.valueOf(true)); //set indentation option serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); //start a tag called "root" serializer.startTag(null, "root"); Log.e("Exception","++xml++ created xml file header"); } catch (Exception e) { Log.e("Exception","++xml++ error occurred while creating xml file"); } </code></pre> <p>procedure to end xml file:</p> <pre><code>final Button buttonEnd = (Button) findViewById(R.id.buttonEnd); buttonEnd.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //XmlSerializer serializer2 = Xml.newSerializer(); try{ serializer.setOutput(outputStream, "UTF-8"); //serializer.endTag(null, "root"); serializer.endDocument(); //write xml data into the FileOutputStream serializer.flush(); serializer = null; //finally we close the file stream outputStream.close(); Log.d("HXMTEST", "+++++ end of creating xml"); }catch (Exception e) { Log.e("Exception","++xml++ error occurred while ending xml file"); } if(mConnectThread != null){ mConnectThread.cancel(); } textview3.setText("the monitoring has been cancelled"); } }); </code></pre> <p>procedure to add nodes:</p> <pre><code>public void AddNodes(String heartBeat, String latitude, String longitude){ //serializer = Xml.newSerializer(); try{ serializer.setOutput(outputStream, "UTF-8"); serializer.startTag(null, "hb"); if(heartBeat != null){ serializer.text(heartBeat); }else{ serializer.text("-1"); } serializer.endTag(null, "hb"); serializer.startTag(null, "latitude"); if(latitude != null){ serializer.text(latitude); }else{ serializer.text("-1"); } serializer.endTag(null, "latitude"); serializer.startTag(null, "longitude"); if(longitude != null){ serializer.text(longitude); }else{ serializer.text("-1"); } serializer.endTag(null, "longitude"); } catch (Exception e) { Log.e("Exception","++xml++ error occurred while adding xml file " +e.toString()); } } </code></pre> <p>it does not throw any exception but create only a bald xml file. i do not know why but when at the function which ends the saving i write <code>serializer.endTag(null, "root");</code> it throws exception array out of bounds. it behaves like it does not save streamly the data.</p> <p><strong>i need something like in objective C is <code>retain</code></strong></p> <p>please help</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.
 

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