Counting XML elements in file on Android
- by CSharperWithJava
Take a simple XML file formatted like this:
<Lists>
<List>
<Note/>
...
<Note/>
</List>
<List>
<Note/>
...
<Note/>
</List>
</Lists>
Each node has some attributes that actually hold the data of the file. I need a very quick way to count the number of each type of element, (List and Note). Lists is simply the root and doesn't matter.
I can do this with a simple string search or something similar, but I need to make this as fast as possible.
Design Parameters:
Must be in java (Android application).
Must AVOID allocating memory as much as possible.
Must return the total number of Note elements and the number of List elements in the file, regardless of location in file.
Number of Lists will typically be small (1-4), and number of notes can potentially be very large (upwards of 1000, typically 100) per file.
I look forward to your suggestions.