Thứ Hai, 28 tháng 7, 2014

Working with SAX

Module 2.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.

B1:Tạo 1 java application,có các components như sau:




B2:tạo tomcat-user.xml


B3:tạo class CounterHandler


B4:Code cho class DemoSax1


Kết quả:


Module2.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. Make necessary arrangements to accept a command line parameter from the user to specify the name of the XML document that holds the list of registered students.

B1:Tạo mới java application như bài trên
B2:Tạo student.xml



B3:code cho class StudentHandler


B4:code chạy chương trình


Kết quả:




Module 2.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 andHa prints an the role of the given user on search completion. This program should include two command-line parameters. The first parameter specifies the tomcat-users.xml file and the second parameter specifies the user name to search in the configuration file.

B1:Tạo mới java application như bài trên
B2:Tạo users.xml


B3:code trong class UserHandler


B4:code trong class DemoSax3


Ket quả:



Nhận xét:SAX giúp cho việc lấy dữ liệu tư file xml nhah hơn và đơn giản bao giờ hết,không tốn quá nhiều bộ nhớ cho việc đọc dữ liêu tư file xml















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

Đăng nhận xét