Squonk
Squonk

Reputation: 48871

Parsing XML file on SD card with Android

I'm running myself around in circles here and the answer should be so simple. I have an XML file downloaded to my phone and saved to SD card. The format is simply...

<programmes>
    <programme>
        <title>Tom and Jerry</title>
        <description>Cat and mouse capers</description>
        <start_time>...</start_time>
    </programme>
    <programme>
        ...
    </programme>
</programmes>

Essentially all I want to do is retrieve all <programme> elements and parse the internal data which will be used to create a SQL INSERT command to populate a SQLite db.

I've tried with DOM but using Document.parse() took me out of memory (the xml file is 3.5MB in size). I've never worked with SAX and can't find an example that makes sense for my idea of how I want to do things and although I've used XPATH, again I can't find any example using the available android apis.

As I said, I'm sure this is easy and it's just my approach is wrong so I'd appreciate any pointers to doing this.

Upvotes: 1

Views: 2658

Answers (1)

Samuh
Samuh

Reputation: 36484

This article details all three methods of XML parsing available on Android: DOM, SAX and pull parser. Hope that helps.

Upvotes: 3

Related Questions