I want to know the difference between the four above types (SAXPaser, XPath, DOM, XMLPullParse) and when should we use each one.
DOM stands for Document Object Model while SAX stands for Simple API for XML parsing. DOM parser load full XML file in-memory and creates a tree representation of XML document, while SAX is an event based XML parser and doesn't load whole XML document into memory.
In PHP there are two major types of XML parsers: Tree-Based Parsers. Event-Based Parsers.
A SAX parser, however, is much more space efficient in case of a big input document (because it creates no internal structure). What's more, it runs faster and is easier to learn than DOM parser because its API is really simple.
SAX Parsing is the Best one to implement than DOM, see the difference between these two in the following:
DOM
The Nodes are in the form of Tree Structure Memory: It Occupies more memory, DOM is only preffered in the case of small XML documents Slower at runtime Stored as an objects Programmatically easy to implement Ease of navigation and use.
SAX
Sequence of events It doesn't use any memory preferred for large documents. Faster at runtime, because of the above mentioned point. Objects are to be created. Need to write code for creating objects In SAX Backward navigation is not possible as it sequentially processes the document
So if you have very large files then you should use SAX parser since it will fire events and releasing them ,nothing is stored in memory ,and using SAX parser you can't access element in a random way there is no going back ! , but Dom let you access any part of the xml file since it keeps the whole file/document in memory .
see this article and you can get what you want by reading the Summary.
also check this link to view performance of different xml parser
Please check below links...
http://steveliles.github.com/comparing_methods_of_xml_parsing_in_android.html
http://xjaphx.wordpress.com/2011/11/01/android-xml-adventure-compare-xml-parsers/
http://www.ibm.com/developerworks/opensource/library/x-android/index.html
http://www.developer.com/ws/android/development-tools/Android-XML-Parser-Performance-3824221-2.htm
http://www.geekinterview.com/question_details/12797
(As Per above Article)
Both SAX and DOM are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation
SAX:
DOM
If we need to find a node and doesnt need to insert or delete we can go with SAX itself otherwise DOM provided we have more memory.
DOM
The Nodes are in the form of Tree Structure Memory: It Occupies more memory, DOM is only preffered in the case of small XML documents..Store the entire XML document into memory befor processing Slower at runtime Stored as an objects Programmatically easy to implement Ease of navigation and use,can traverse in any direction. We can insert or delete,alter nodes.
SAX : use when you want to access XML ( not alter XML)
Sequence of events It doesn't use any memory preferred for large documents.Doesn't store the XML in memory before processing Faster at runtime, because of the above mentioned point. Objects are to be created. Need to write code for creating objects In SAX Backward navigation is not possible as it sequentially processes the document,top to bottom traversing We can't insert or delete a node
XPATH: Xpath is useful when you only need a couple of values from the XML document and you know where to find them(you know the path of the data./root/item/challange/text)
XMLPullParser: Fast and requires less memory with DOM
Source: http://www.time2ask.com/ http://www.time2ask.com/Android/The-difference-among-SAX-ParserXPathDOMXMLPullParser/_2361836
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With