tailieunhanh - Java & XML 2nd Edition solutions to real world problems phần 3

Các giao diện được cung cấp trong gói SAX sẽ trở thành một phần quan trọng của bộ công cụ của bất kỳ lập trình để xử lý XML. Mặc dù các lớp SAX là nhỏ và ít về số lượng, họ cung cấp một khuôn khổ quan trọng | Java XML 2nd Edition chain or pipeline of events. To understand what I mean by a pipeline here s the normal flow of a SAX parse Events in an XML document are passed to the SAX reader. The SAX reader and registered handlers pass events and data to an application. What developers started realizing though is that it is simple to insert one or more additional links into this chain Events in an XML document are passed to the SAX reader. The SAX reader performs some processing and passes information to another SAX reader. Repeat until all SAX processing is done. Finally the SAX reader and registered handlers pass events and data to an application. It s the middle steps that introduce a pipeline where one reader that performed specific processing passes its information on to another reader repeatedly instead of having to lump all code into one reader. When this pipeline is set up with multiple readers modular and efficient programming results. And that s what the XMLFilter class allows for chaining of XMLReader implementations through filtering. Enhancing this even further is the class which provides a helpful implementation of XMLFilter. It is the convergence of an XMLFilter and the DefaultHandler class I showed you in the last section the XMLFilterImpl class implements XMLFilter ContentHandler ErrorHandler EntityResolver and DTDHandler providing pass-through versions of each method of each handler. In other words it sets up a pipeline for all SAX events allowing your code to override any methods that need to insert processing into the pipeline. Let s use one of these filters. Example 4-5 is a working ready-to-use filter. You re past the basics so we will move through this rapidly. Example 4-5. NamespaceFilter class package javaxml2 import import import import public class NamespaceFilter extends XMLFilterImpl The old URI to replace .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.