Difference among XML SAX parser, Pull parser & DOM Parser in android

I want to know what’s the difference between XML SAX parser, Pull parser & DOM parser in Android. In which condition, which one is better in performance and implementation?

Thanx.
Khobaib.

  • EOFException in Retrofit while executing synchronous PUT requests
  • How can you tell when a layout has been drawn?
  • android.content.res.Resources$NotFoundException for ic_sync_black_24dp.xml
  • How to stop Eclipse from trying to run XML files?
  • How do android screen coordinates work?
  • “Could not find class 'android.support.v4.app.FragmentActivity'” Error
  • Why so many GC_FOR_ALLOC in a simple app?
  • Simulate no network using Retrofit and MockWebServer
  • Styling EditText view with shape drawable to look similar to new holographic theme for Android < 3.0
  • How can I add my spinner to the ActionBar?
  • Is it possible to start activity through adb shell?
  • Set rowSpan or colSpan of a child of a GridLayout programmatically?
  • 4 Solutions collect form web for “Difference among XML SAX parser, Pull parser & DOM Parser in android”

    Dom Parser – It uses object based approach. i.e., it first loads the entire XML in memory, converts the XML nodes into objects and then starts parsing them. So, it is pretty slower.

    SAX and PULL Parser – they use event based approach. Both are almost same in terms of memory and performance. However there are few distinguishing situations on when to use them as described below.

    Dom Parser – Use it when you need to validate the entire XML before parsing.
    Never use it when the XML is too large and validation can be compromised.
    Once it starts parsing, it parses from starting node to ending node. there is no way to parse only particular nodes.

    SAX – Use it when you want to parse the entire XML.
    Once it starts parsing, it parses from starting node to ending node. there is no way to parse only particular nodes.

    PULL – Use it when you don’t want to parse the entire XML. It is easier to implement than SAX, because you don’t have to maintain the state of your parser. You can pull only a particular node you are interested at.

    My suggestion is – Need validation – Go for DOM, File size is small or you are not interested in parsing of entire XML- Go for PULL, File size is large or you need to parse the entire XML file – Go for SAX.

    Sax Parser : Simple API of XML
    Parse node to node, using top-down traversing, parse without storing xml,
    Faster compared to Dom
    Manipulating of node like insertion or deletion is allowed.
    Needs SAXParserFactory

    Dom Parser : Document Object Model
    Stores entire xml in memory before processing, traverse in any direction,
    Manipulating of node like insertion or deletion is NOT allowed.
    Needs DocumentBuilderFactory

    Pull Parser: It provides more control and speed from the above two. Needs pullParserFactory

    This is not a programming question, but anyways you can get started by looking at SAX parser vs XMLPull parser

    I would suggest doing more research before posting.

    As far as performance, SAX will generally use much less memory. And you only handle the events you want, e.g. startElement(), startDocument(), endElement(), etc. etc., and thus you will only save specific data you want. DOM will load the entire XML file into memory.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.