Salman
Salman

Reputation: 1

How to parse large xml file with Dom Parser in Android

I'm trying to parse large xml with Dom parser in android.The xml file size exceed 1Mb
I'm using this code,

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();        
        Document doc = docBuilder.parse(istream); // normalize text representation
        doc.getDocumentElement().normalize();

i got an out of memory exception, at

Document doc = docBuilder.parse(istream); //this line

Is there any way to cope with this issue , I'm working on android eclipse emulator. Any help in this regards greatly appreciated. Thanks

Upvotes: 0

Views: 749

Answers (1)

weekens
weekens

Reputation: 8292

Maybe use SAX instead of DOM? It is event-based and doesn't build huge in-memory structures.

Upvotes: 3

Related Questions