問題描述
我正在使用 SAX Parser 解析 XML 文檔.
I am parsing XML Document using SAX Parser.
我想知道使用 DOM、SAX Parser 或 XMLPullParser 哪個更好更快.
I want to know which is better and faster to work with DOM, SAX Parser or XMLPullParser.
推薦答案
這取決于你在做什么,如果你有非常大的文件,那么你應該使用 SAX 解析器,因為它會觸發(fā)事件并釋放它們,沒有任何東西存儲在內(nèi)存,并且使用 SAX 解析器,您不能以隨機方式訪問元素,沒有回頭路!,但 Dom 允許您訪問 xml 文件的任何部分,因為它將整個文件/文檔保存在內(nèi)存中.希望這個回答你的問題.
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 .
如果您想知道哪個最快的解析器 Xerces 將是最快的,您會發(fā)現(xiàn) SAX解析器應該給你比 Dom 更高的性能
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
這篇關(guān)于Android:DOM vs SAX vs XMLPullParser 解析?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!