First, DOM (Document Object Model)
A set of interfaces are defined for the resolution version of the XML document. The parser reads the entire document and then builds a tree structure that resides in memory, then the code can use the DOM interface to operate this tree structure.
Advantages: The entire document tree is in memory, easy to operate; support for deletion, modification, rearrangement and other functions;
Disadvantages: Turn the entire document into memory (including useless nodes), waste time and space;
Use occasion: Once the document is parsed, you need to access these data multiple times;
Hardware resources are sufficient (memory, CPU)
Second, SAX
In order to solve the problem of DOM, SAX appears.
SAX, event driver. When the parser finds the elements, the element ends, the start or end of the text, the start or end of the document is sent, and the programmer writes the code that responds to these events and saves the data.
Advantages: No need to transfer to the entire document in advance, accounting for less resources;
SAX parser code is smaller than the DOM parser code, suitable for applet, download
Disadvantages: Not lasting; after the incident, if the data is not saved, the data is lost;
Stateless; only the text can be obtained from the event, but I don't know which element belongs to the text;
Use occasion: applet;
Simply need a small amount of content of the XML document, very much attention;
Machine memory;
Third, JDOM
In order to reduce the amount of DOM, SAX encoding, JDOM appears;
Advantages: 20-80 principles, greatly reduce the amount of code
Use occasion: It is simple to implement, such as resolution, creation, etc.
Java program
But at the bottom, JDOM is still using SAX (most common), DOM, Xanan
Four, JAPX
Unified programming interface for multiple XML parsers
Replace the parser, do not change the code
Use occasion: If you do not need to use JDOM, JAPX is generally recommended to isolate the code with various parsers.