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

Reply via email to