Thứ Bảy, 26 tháng 7, 2014

Use SAX to read XML file

Demo 1:

Create a program to accept the tomcat-users.xml file as a command line parameter and count the number of users defined in this configuration file. At the end of processing, it requires to print the number of users on the console.

Bước 1: Tạo new project



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


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



Bước 4: Viết code cho file CounterTheNumber.java


Kết quả:


Demohttps://drive.google.com/file/d/0B-EFzewQLSMDTGp0T3lpek5BcFE/edit?usp=sharing

Demo 2:

Create the student.xml file that stores a list of registered students. Write a program for printing the name and ID of all registered students provided in student.xml.

Bước 1: Tạo file student.xml


Bước 2: Tạo fileStudent.java



Bước 3: Viết code cho file chạy chương trìn



Kết quả:

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

Demo 3:

Write a program which demonstrates the use of SAX parser for a simple search in XML document. The program searches a specified user in the tomcat-users.xml file and prints an the role of the given user on search completion.

Bước 1: Tạo file user.xml

Bước 2: Tạo file User.java


Bước 3: Viết code cho file chạy chương trình


Kết quả:


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

Nhận xét:

Ưu điểm của SAX:
   -Đơn giản Sử dụng ít bộ nhớ
   -Tốc độ xử lý nhanh
   -Tập trung vào dữ liệu hiện hành
   -Dễ sử dụng để lọc dữ liệu

Nhược điểm của SAX
  -Không thể tác động lên dữ liệu XML
  -Chế độ lưu trữ trạng thái phức tạp
  -Khó khăn khi phân tích cấu trúc XML lớn

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

Đăng nhận xét