On Mon, Aug 29, 2011 at 6:30 AM, Nikolay Elenkov <[email protected]> wrote: > On Mon, Aug 29, 2011 at 1:17 PM, Michael Banzon <[email protected]> wrote: >> On Mon, Aug 29, 2011 at 3:07 AM, Nikolay Elenkov >> <[email protected]> wrote: >>> On Mon, Aug 29, 2011 at 6:15 AM, bob <[email protected]> wrote: >>>> I'm using this on Android to fix a corrupted Xml file that's about >>>> 2.5MB: >>>> >>>> xml = xml.replaceAll("&", "&"); >>>> >>>> However, that statement causes an out of memory error. Any ideas? >>>> >>> >>> Don't read the whole thing as one huge string, process >>> it line by line or element by element, whatever works. >> >> If the purpose is to fix broken XML I wouldn't recommend to read by element >> ;-) >> >> Line by line should be fine. > > Depending on how broken it is, it might not be a good idea, yes. The > thing is, the file might not have any new lines, and in that case he might > end up reading the whole thing again. So, I guess the correct (though a > bit general) advice would be 'find some delimiter to split the file and > process in pieces'.
Right. And an even more general advice - fix the source ;-) If the XML producer is something you control this should clearly be fixed. If can communicate with the controller, ask them to fix it. I know it's "just" XML, but their program/system/employe produce invalid output. -- Michael Banzon http://michaelbanzon.com/ -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

