Difference between Dom parser and Xerces Parser

2019-05-27 01:03发布

问题:

Hey, can anyone please tell me, what are difference between "Dom parser" and "Xerces Parser". What are the advantage and Disadvantages of either.

回答1:

Xerces is a DOM parser. It's the Apache implementation in Java or C++.

The two you want to think about are SAX and DOM. DOM creates an object tree in memory; SAX does not. You can manipulate the object tree after the DOM is done parsing; SAX uses an event model to process XML on the fly.

Either SAX or DOM will "work". Your choice is usually based on whether or not you'll keep it in memory to manipulate it or process it in place. If the XML stream is gigabytes, you might not be able to store it all at once. In that case, SAX is a good choice because you can work with it on the fly as you parse.

Google is your friend: Fire it up to learn about DOM4J and JDOM.

I'd recommend JDOM if you're writing Java. It takes care of a lot of the boilerplate stuff.



回答2:

there are two ways to parse an xml file in Xerces.viz SAX & DOM. SAX Parser:

  1. Event based model.
  2. Serial access (flow of events).
  3. Low memory usage (only events are generated).
  4. To process parts of the document (catching relevant events).
  5. To process the document only once.
  6. Backward navigation is not possible as it sequentially processes the document.
  7. Objects are to be created.

DOM Parser:

  1. (Object based)Tree data structure.
  2. Random access (in-memory data structure).
  3. High memory usage (the document is loaded into memory).
  4. To edit the document (processing the in-memory data structure).
  5. To process multiple times (document loaded in memory).
  6. Ease of navigation.
  7. Stored as objects.