views:

56

answers:

1

I'm parsing large XML document using pull parser (org.xmlpull.v1.XmlPullParser). When I reach specific node I want to grab it and all its children as chunk of text (or just children is OK too) and save as String. What would be efficient way of achieving this? Anything better than (in essence) buffer.append('<').append(xpp.getName()).append('>')?

Here's an example

<root id="root">
    <node>
      <grab-all-inside>
          <!-- bunch of nodes, attributes etc. that needs to be saved as text -->
      </grab-all-inside>
    </node>
    <node>
      <grab-all-inside>
          <!-- bunch of nodes, attributes etc. that needs to be saved as text -->
      </grab-all-inside>
    </node>
    <node>
      <grab-all-inside>
          <!-- bunch of nodes, attributes etc. that needs to be saved as text -->
      </grab-all-inside>
    </node>
</root>

P.S. If you think I'm better off using some other parser or technique I'm open for suggestions. Just as a side note - these text chunks will be serialized to db with premise that at some point these will be extracted and parsed

A: 

I suspect your append() calls are as good as it gets. Those are each individual events in a pull parser.

If this is an XML resource, consider using string resources instead. I know that for Android 1.6+ they can contain light HTML markup, and it may be they can contain arbitrary markup, just treated as a string -- haven't tried it. Or, create raw resources for each node's contents and read the whole thing in as a string.

CommonsWare
I have to support 1.5 - it is still about 12% of my app's traffic according to Flurry. I get feed as XML, parsing is trivial but pretty involved. I want to cash limited number of updates and I have a feeling that instead of monkeying with saving bunch of objects to bunch of tables I'm better off with saving piece of text into a single column and then reparsing it using the same routine. But it kills me to think that I need to reassamble XML snippet from parts when it's readily available
DroidIn.net
Yep - ended up using buffering, thanks Mark
DroidIn.net