I’m trying to parse a 100KB XML file with a 1 level hierarchy in Java, J2ME in particular. The problem is that the parsing of the XML file is taking over 1MB, despite it being 100KB in size, which is causing an OOME.
Is it normal for the parsing of an XML to take over 10x its size in memory? Or is there something wrong with the parser?
If it is normal, is there any other way of doing this? I was thinking of maybe using JSON instead, or perhaps just iterate through a normal text file since the XML has only 1 level of hierarchy, and its partitioning is identical.
How are you parsing it ? Reading it using DOM will load the entire object model into memory, whereas using a SAX parser will read it little by little and call your code for each element, text-node etc. This means it’ll consume far less space since it’s not storing anything, and you’re in control of what you record.