Use SAX to read xml file
Cấu trúc của sax
Sax Reader gồm 4 thành phần cơ bản : content handler, error handler, dtd hanlder, entity hanlder.
The registered students provided in student.xml
Main class
inXML 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.
This program should include two command-line parameters. The first parameter
specifies the tomcat-users.xmlfile and the second parameter specifies the user
name to search in the configuration file.
Xml file having user list
Enter name of xml file to read from:
Enter enter search key:
The student's detail (name, password, roles) having the name matched the key search was displayed :
Practice assingment
Module 2.1
Create a program to accept the tomcat-users.xm lfile 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.
tomcat-user.xml
main class
Handling file that extends DefaultHnndler class
Number of users defined in the configuration file were displayed on the console
Module 2.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.The registered students provided in student.xml
Main class
The registered students list was displayed:
Module 2.3
Write a program which demonstrates the use of SAX parser for a simple searchinXML 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.
This program should include two command-line parameters. The first parameter
specifies the tomcat-users.xmlfile and the second parameter specifies the user
name to search in the configuration file.
Xml file having user list
Enter name of xml file to read from:
Enter enter search key:
The student's detail (name, password, roles) having the name matched the key search was displayed :
Không có nhận xét nào:
Đăng nhận xét