Thứ Sáu, 1 tháng 8, 2014

Validate xml in SAX

Demo 1: Create an application, which demonstrates the generation of an error during parsing an XML document. Write the code for handling different types of errors and exceptions. Define an endDocument() method to override the contentHandler. Declare a method to override the error method of errorhandler.


Bước 1: Tạo new project



Bước 2: Tạo file tomcat-users.xml


Bước 3: Tạo trang HandlerReader.java

Bước 4: Viết code cho file main


Kết quả:


Demo: https://drive.google.com/file/d/0B-EFzewQLSMDMW9xMDR0MC0taDA/edit?usp=sharing

Demo 2: Create an application, which demonstrates the implementations of DTDHandler interface methods. As the DefaultHandler implements the DTDHandler interface, you need to override the desired methods of DTDHandler interface.

Bước 1: Tạo new project



Bước 2: Tạo file note.xml

Bước 3: Tạo file TagDTDHandler.java

Bước 4: Viết code cho file DTDHandlerDemo.java để chạy chương trình


Kết quả:


Demo: https://drive.google.com/file/d/0B-EFzewQLSMDcjJGLXAtYnE3TU0/edit?usp=sharing

 Demo 3: Create an XML file Report.xml that contains the sales data for this financial year. Create an application that demonstrates the implementations of LexicalHandler interface methods .The application should display the number of entities, CDATA, and comments in the Report.xml document.

Bước 1: Tạo new project



Bước 2: Tạo file Report.xml


Bước 3: Viết code cho file main

Các mothed


Code chạy chương trình

Kết quả


Demo: https://drive.google.com/file/d/0B-EFzewQLSMDdnh2cWZodDMzZDQ/edit?usp=sharing

Nhận xét:
- Các lớp override trong DefaultHandler giúp SAX kiểm soát lỗi dữ liệu tốt hơn
- Ứng dụng sẽ được kiểm soát và an toàn hơn
- Việc xây dựng web sẽ trở nên đơn giản và tối ưu hơn

Không có nhận xét nào:

Đăng nhận xét