XML programming interface under Java Compare: DOM SAX JDOM JAXP Select BLOG from LPHPC

xiaoxiao2021-03-06  40

I. DOM (Document Object Model) defines a set of interfaces 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; supports multiple functions such as deletion, modification, rearrangement; Disadvantages: Turn the entire document into memory (including useless nodes), waste time and space; use occasion: once parsing Documentation also needs to access these data multiple times; the hardware resource is sufficient (memory, CPU) II. SAX is SAX in order to solve DOM. 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, small resources; SAX parser code is small than the DOM parser code, suitable for applet, download shortcomings: not lasting; after the incident, if there is no saving data, then data is lost; Status; only text from the event, but I don't know which element belongs to the text; use occasion: applet; only the small amount of content of the XML document, very small back; the machine is less, three, JDom to reduce DOM, SAX Coding amount, the JDOM; Advantages: 20-80 principles, greatly reduces code quantity usage: Simple features to be implemented, such as resolution, creation of Java programs but on the bottom, JDOM or SAX (most common), DOM Xanan 4, JAPX provides a unified programming interface to replace the resolution for multiple XML parsers, without changing code usage: If you do not need JDOM, JAPX is generally recommended to implement detail of the implementation of the code with various parsers.

转载请注明原文地址:https://www.9cbs.com/read-57435.html

New Post(0)