Code Golf: Counting XML elements in file on Android
Posted
by CSharperWithJava
on Stack Overflow
See other posts from Stack Overflow
or by CSharperWithJava
Published on 2010-04-06T16:29:20Z
Indexed on
2010/04/06
16:33 UTC
Read the original article
Hit count: 246
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.
© Stack Overflow or respective owner