[android-developers] Re: DOM, SAX or XMLPullParser ? Any suggestions ?
Bear in mind that speed (DOM v SAX) may not be much of an issue for
parsing smaller amounts of XML, or where for some reason you can't use
the parsed data until you've parsed the entire XML document anyway:
SAX shines where you can (and need to) use data (e.g. to update a GUI)
as soon as it's parsed. The speed bottleneck is often somewhere else,
such as the HTTP request/response cycle time, rendering or other
processing.
Likewise for DOM: DOM documents will take more memory than using SAX,
but this may not be a problem if you're careful.
A really simple DOM utility library would be useful, e.g. 'get me
value of the attribute foo on first child blah element'.
Sam
It's more the memory taken by DOM documents.
On Feb 5, 1:45 pm, "Emre A. Yavuz" <eayl...@hotmail.com> wrote:
> Hi,
>
> We need to convert XML messages to a stream or string which can then be sent via sockets. However, Android does not support the standard javax classes that are used to convert a DOM XML object to a stream. Besides, as far as I know, DOM parser reads all of the XML document into the memory before allowing to use the DOM APIs to transverse the XML tree in order to retrieve the data you want. This may be simpler than the SAX-based implementations, however DOM generally consumes more memory as everything is read into the memory first although this won't effect the performance on a mobile device much, unless the size of the XML document is large.
>
> On the other hand, using SAX or XML pull parser may be better options due to the extra utilities provided for them. XML PullParser works similarly to StAX which is also not supported by the Android platform. This class seems to allow your application code to pull or seek events from the parser, as opposed to the SAX parser which automatically pushes events to the handler. You can also set a flag to identify when you reach the end of the content that you are interested in. This lets you halt the reading of the XML document early, as you know that the code will not care about the rest of the document. This can be very useful, especially if you only need a small portion of the XML document being accessed. That means you can reduce the parsing time by stopping the parsing as soon as possible especially when the size of the XML document is large.
>
> I was wondering whether anybody, who has experience using the XmlPullParser class or others on the Android platform, has anything to say about its efficiency, well-known problems if any, suggestions for a better alternative, links for sample code etc.
>
> Cheers,
>
> Emre
>
> _________________________________________________________________
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home