The difference among : SAX Parser,XPath,DOM,XMLPul

2019-03-20 15:18发布

I want to know the difference between the four above types (SAXPaser, XPath, DOM, XMLPullParse) and when should we use each one.

3条回答
我只想做你的唯一
2楼-- · 2019-03-20 15:29

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

enter image description here

查看更多
▲ chillily
3楼-- · 2019-03-20 15:32

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:

  1. Parses node by node
  2. Doesnt store the XML in memory
  3. We cant insert or delete a node
  4. Top to bottom traversing

DOM

  1. Stores the entire XML document into memory before processing
  2. Occupies more memory
  3. We can insert or delete nodes
  4. Traverse in any direction.

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.

查看更多
乱世女痞
4楼-- · 2019-03-20 15:44

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

查看更多
登录 后发表回答