You're not "appending", you're "inserting". You basically will need to read/write the entire file.
On May 16, 1:07 pm, surya tej <akkirajusurya...@gmail.com> wrote: > Thanks a lot folks..for your response > > My XML format is > .................................................................. > <Test> > <attempt> > </attempt> > <QuestionSet> > <Question type = 1 path="images/a.jpg"> > <Options type = 1 value ="1" ></options> > <Options type = 1 value ="2" ></options> > <Options type = 1 value ="3" ></options> > <Options type = 1 value ="4" ></options> > </Question> > <answer>A</answer> > </QuestionSet> > </Test> > > .................................................................. > > I need this XML file for a test taking application.When the user submits his > exam . i am able to evaluate his score.then i need this score to be > appended to the above XML .So that the XML should look like > > .................................................................. > <Test> > <attempt> > <score = "90"> > </attempt> > <QuestionSet> > <Question type = 1 path="images/a.jpg"> > <Options type = 1 value ="1" ></options> > <Options type = 1 value ="2" ></options> > <Options type = 1 value ="3" ></options> > <Options type = 1 value ="4" ></options> > </Question> > <answer>A</answer> > </QuestionSet> > </Test> > > .................................................................. > > i.e a new score tag is created and appended to the existing XML. > > Kindly help me in this regard with code . > > thanks in advance. > > On Mon, May 16, 2011 at 4:02 AM, Miguel Morales > <therevolti...@gmail.com>wrote: > > > > > Hmm, I'd probably do it one of two ways depending on how big the xml file > > is expected to grow. > > > If it's relatively small, read it into memory, deserialize it, find the > > node/tag where you wish to append your node, append it and then re-serialize > > it into the same file. But that's only if it's small. > > > If it's larger, probably stream de-serialize the file, look for the tag and > > append the node there. (and don't store to memory any tags you don't care > > about.) > > > Obviously any de-serialization will have to take place in a worker thread. > > > On Sun, May 15, 2011 at 3:02 PM, DanH <danhi...@ieee.org> wrote: > > >> Another alternative is a journaled approach. Write the updates to a > >> journal, then merge them with the main file from time to time in a > >> "batch" processing step. > > >> On May 15, 4:57 pm, Bob Kerns <r...@acm.org> wrote: > >> > Simple, yes, but it performs as O(n^2). As your file gets longer and > >> longer, > >> > your application will perform slower and slower. If you don't take care > >> to > >> > do it off the UI thread, you will eventually start getting force-closes > >> > because it stalls out the UI thread. > > >> > Not generally recommended. > > >> > All of these solutions have potential issues with incomplete writes, due > >> to > >> > the application being shut down in mid-write. > > >> > A more robust solution, also quite simple, is to stick all the data into > >> a > >> > database -- and output it as XML at the point you need XML. In most > >> > scenarios, this is the approach I would recommend. > > >> > On Sunday, May 15, 2011 7:47:34 AM UTC-7, lbendlin wrote: > > >> > > Throw away your requirement ("no rewriting of the file") and you have > >> a > >> > > simple solution. > > >> -- > >> You received this message because you are subscribed to the Google > >> Groups "Android Developers" group. > >> To post to this group, send email to android-developers@googlegroups.com > >> To unsubscribe from this group, send email to > >> android-developers+unsubscr...@googlegroups.com > >> For more options, visit this group at > >>http://groups.google.com/group/android-developers?hl=en > > > -- > > ~ Jeremiah:9:23-24 > > Android 2D MMORPG:http://solrpg.com/, > >http://www.youtube.com/user/revoltingx > > > -- > > You received this message because you are subscribed to the Google > > Groups "Android Developers" group. > > To post to this group, send email to android-developers@googlegroups.com > > To unsubscribe from this group, send email to > > android-developers+unsubscr...@googlegroups.com > > For more options, visit this group at > >http://groups.google.com/group/android-developers?hl=en > > -- > Thanks & Regards, > > Suryatej, > 9247714040. > > Please Save paper, Save trees. > Please don't print this email and documents unless it is really necessary. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en