Sept. 6, 2010, 6:47 a.m.
posted by reo
Simple API for XMLEric Armstrong In This Chapter 5.3 Echoing an XML File with the SAX Parser 5.4 Adding Additional Event Handlers 5.5 Handling Errors with the Nonvalidating Parser 5.6 Substituting and Inserting Text 5.7 Creating a Document Type Definition (DTD) 5.8 DTD's Effect on the Nonvalidating Parser 5.9 Defining Attributes and Entities in the DTD 5.10 Referencing Binary Entities 5.11 Using the Validating Parser 5.12 Defining Parameter Entities and Conditional Sections 5.13 Parsing the Parameterized DTD 5.15 Using the DTDHandler and EntityResolver In this chapter we focus on the Simple API for XML (SAX), an event-driven, serial-access mechanism for accessing XML documents. This is the protocol that most servlets and network-oriented programs will want to use to transmit and receive XML documents, because it's the fastest and least memory-intensive mechanism that is currently available for dealing with XML documents. The SAX protocol requires a lot more programming than the Document Object Model (DOM). It's an event-driven model (you provide the callback methods, and the parser invokes them as it reads the XML data), which 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. For those reasons, developers who are writing a user-oriented application that displays an XML document and possibly modifies it will want to use the DOM mechanism described in the next part of the tutorial, Document Object Model (page 149). However, even if you plan to do build DOM apps exclusively, there are several important reasons for familiarizing yourself with the SAX model:
|
- Comment