tailieunhanh - Pro XML Development with Java Technology 2006 phần 3
PI đơn giản cho XML Xoay quanh các vấn đề về DOM, các thành viên XML-DEV (đứng đầu là David Megginson) đã tạo nên SAX. SAX có vài đặc điểm xác định rõ hơn các lo lắng về DOM: Bộ kiểm ngữ SAX gửi các sự kiện đến mã của bạn. Bộ kiểm ngữ sẽ cho bạn biết khi nó tìm thấy bắt đầu, kết thúc của một phần tử, từ ngữ, bắt đầu và kết thúc của văn bản, | CHAPTER 2 PARSING XML DOCUMENTS 49 ContentHandler is the main interface that an application needs to implement because it provides event notification about the parsing events. The DefaultHandler class provides a default implementation of the ContentHandler interface. To handle SAX parser events an application can either define a class that implements the ContentHandler interface or define a class that extends the DefaultHandler class. You use the SAXParser class to parse an XML document. You obtain a SAXParser object from a SAXParserFactory object. To obtain a SAX parser you need to first create an instance of the SAXParserFactory using the static method newInstance as shown in the following example SAXParserFactory factory JAXP Pluggability for SAX JAXP provides complete pluggability for the SAXParserFactory implementation classes. This means the SAXParserFactory implementation class is not a fixed class. Instead the SAXParserFactory implementation class is obtained by JAXP using the following lookup procedure 1. Use the . system property to determine the factory class to load. 2. Use the specified in the lib file under the JRE directory to determine the factory class to load. JAXP reads this file only once and the property values defined in this file are cached by JAXP. 3. Files in the META-INF services directory within a JAR file are deemed service provider configuration files. Use the Services API and obtain the factory class name from the META-INF services javax .xml. parsers .SAXParserFactory file contained in any JAR file in the runtime classpath. 4. Use the default SAXParserFactory class included in the J2SE platform. If validation is desired set the validating attribute on factory to true true If the validation attribute of the SAXParserFactory object is set to true the parser obtained from such a factory .
đang nạp các trang xem trước