XML parser SAX, DOM, JDOM, JAXP advantages and disadvantages

xiaoxiao2021-03-06  27

Dom builds the entire document resides in memory. If the document is large, it will require great memory.

DOM creates objects that represent each thing in the original document, including elements, text, properties, and spaces. If you only need to pay attention to a small part of the original document, create those objects that never use are extremely wasteful.

The DOM parser must read the entire document before your code gets control. For very large documents, this will cause significant delays.

The SAX parser sends an event to your code. When the parser finds the elements, the element is ended, the text, the beginning or end of the document, will tell you. You can decide what event is important to you, and you can decide what type of data structure to create to save data from these events. If you do not explicitly save data from an event, it is discarded.

The SAX parser does not create any object at all, it just passes the event to your application. If you want to create an object based on those events, this will be done by you.

The SAX parser starts sending events when parsing. When the parser discovers the document, the element starts and text, etc., the code will receive an event. Your app can start generating results immediately; you don't have to wait until the entire document is parsed. Sometimes, if you only find some of the content in the document, once you find what you want to find, you can throw an exception. This exception will stop the SAX parser, then the code does anything it needs to do with the data it finds.

The SAX event is stateless. When the SAX parser found text in the XML document, it sends an event to your code. This event only gives you the text discovered; it doesn't tell you what element contains that text. If you want to know this, you must write your status management code yourself.

SAX events are not lasting. If the application requires a data structure to model the XML document, you must write that code yourself. If you need to access the data from the SAX event, you have to store the data in the code, then you have to resolve the document again.

SAX is not controlled by a centralized management. Although this has not yet caused any problems so far, if SAX is like W

3C

If such an organization is controlled, some developers will feel more.

The main feature of JDOM is that it greatly reduces the number of codes you must write. The length of the JDOM application is usually one-third of the DOM application, approximately half of the SAX application.

JAXP provides public interfaces for using DOM, SAX, and XSLT processing XML documents

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

New Post(0)