In order to make the XML document can be identified and processed by application, a way to read an XML document must be provided. Of course, you may say that XML is not a text file? Can you read it with java.IO package? XML files are not simple Plain Text, which has their own structure and descriptive, and we need further on the basic I / O. There are two different ways of reading common XML: SAX and DOM, let's take a look at:
SAX is the abbreviation of Simple API for XML, as the name suggests, is the simple API of the XML, just like the name of its name, SAX is much more straightforward than the DOM. In essence, SAX is an event-driven, for example, when reading the XML file to a tag, the event is passed to the application, so the application is handled accordingly, and the application only knows already read at this time. The part of the content is taken, and there is no knowledge of the remaining XML data. This is the limitations of SAX, while SAX is a part of the handle, it is quite fast.
DOM is the abbreviation of Document Object Model. This name is to be more abstract, it is a one-time handle the entire XML document and then the component is a complete tree object model, so its speed is more than SAX. A lot of slow, but there is a more complete view for the XML document, which is essential.
Usually we use the XML API to support these two modes. When you encounter specific problems, we can determine which model uses based on the complexity, scale, and our needs of the document.