Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: DOM vs SAX vs XMLPullParser parsing?

I am parsing XML Document using SAX Parser.

I want to know which is better and faster to work with DOM, SAX Parser or XMLPullParser.

like image 696
Basbous Avatar asked Jan 17 '12 10:01

Basbous


People also ask

Is SAX parser faster than DOM?

SAX Parser is slower than DOM Parser.

What is the difference between DOM parser and SAX parser?

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.

What advantages does a SAX parser have over a DOM parser?

1)SAX is faster than DOM. 2)SAX is good for large documents because it takes comparitively less memory than Dom. 3)SAX takes less time to read a document where as Dom takes more time. 4)With SAX we can access data but we can't modify data.


1 Answers

it depends on what are you doing , 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 . hope this answer you question .

if you want to know which fastest parser Xerces is going to be the fastest you'll find and SAX parser should give you more performance than Dom

like image 57
confucius Avatar answered Sep 18 '22 14:09

confucius