DOM: The document Object Model, which belongs to the documentation driver. When parsing an XML file, you need to read the entire XML document, exist in memory, and build the DOM tree, generating each node object on the DOM tree. After the DOM tree is generated, any part of the file tree can be stored or read at will, and can be read repeatedly with no limit to the number of times.
Sax: Simple Api for XML, which is event-driven, does not need to read the entire document, the process of reading the document is also the Sax parsing process, event-driven refers to a callback (callback) mechanism of the program run method. Sax has a low memory requirement because it allows developers to decide what labels they want to handle, especially if they need to work on some of the data contained in the document, and Sax is better able to scale.
Comprehensive:
Dom Pros and Cons: can read and modify any part of the file tree, but because of the need to save the document in memory before parsing and generate a document tree (the resulting document tree is time-consuming), so the resolution is slow and large memory, suitable for parsing small and medium-sized documents.
Sax pros and Cons: only sequential access to read, cannot modify, can partially read the document, so the resolution is fast, suitable for parsing large documents, but because of the need to establish their own amount of XML object model, increased the difficulty of development.
Sax parsing vs. Dom parsing