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

Validate XML using validator and ErrorHandler

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 Java Application như các Demo bài trước.
Bước 2: Tạo file tomcat-users.xml

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

Bước 4: Xử lý code trong file chạy chương trình.

Demo chương trình.
Demo các bạn có thể tải tại đây.

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 Java Application như các Demo trước.
Bước 2: Tạo file test.xml

Bước 3: Tạo file TagDTDHandler.java
 
Bước 4: Xử lí code trong file chạy chương trình.

Demo chương trình
Các bạn có thể tải Demo tại đây.

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 Java Application như các Demo trước.
Bước 2: Tạo file test.xml

Xử lí code trong file chạy chương trình.

Các phương thức Override.

Demo chương trình.
Các bạn có thể tải Demo tại đây.
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 được kiểm soát và an toàn hơn.
- Việc xây dựng ứng dụng 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