SAX是Simple API for XML的简称。
什么是SAX?
Simple API for XML (SAX), an event-driven, serial-access mechanism for accessing XML documents.
SAX is an event-driven model (you provide the callback methods, and the parser invokes them as it reads the XML data), and that makes it harder to visualize. Finally, you can't "back up" to an earlier part of the document, or rearrange it, any more than you can back up a serial data stream or rearrange characters you have read from that stream.
很长的一段话,但是我以前使用过一个爬虫的程序,知道两种解析方法。一种是,你必须按照文章读取的顺序来解析文章。第二种,需要解析的文章已经被读到内存当中,并且用一种格式化的方式储存起来,你可以随即访问这个文章的某个元素,并且可以根据这个元素访问到跟这个元素有关系的元素。
另外SAX和DOM方式有一定的联系。
Same Error Handling: The same kinds of exceptions are generated by the SAX and DOM APIs, so the error handling code is virtually identical.
Same Error Handling: The same kinds of exceptions are generated by the SAX and DOM APIs, so the error handling code is virtually identical.
Handling Validation Errors: By default, the specifications require that validation errors (which you'll learn more about in this part of the tutorial) are ignored. If you want to throw an exception in the event of a validation error (and you probably do), then you need to understand how SAX error handling works.
Converting Existing Data: As you'll see in Chapter 6, there is a mechanism you can use to convert an existing data set to XML. However, taking advantage of that mechanism requires an understanding of the SAX model.
Converting Existing Data: As you'll see in Chapter 6, there is a mechanism you can use to convert an existing data set to XML. However, taking advantage of that mechanism requires an understanding of the SAX model.
SAX,StAX,DOM之间的联系和区别
SAX:fast and efficient,not construct a internal structure.
StAX:a little different from SAX,use it to get the next node from any point of the code.
DOM:struct a more interactive view of document,easy to modify text or element in the xml document.

