Android XML - saving text chunks during pull parsing
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 chi开发者_如何学Cldren 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
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.
精彩评论