Use Xpath
Module 9 :
In an organization, five hundred employees are working. Out of
which some are apprentices. The Delivery Unit Head of that organization
gave you the responsibility to develop a software, with which you can
find the details of apprentices. Use the below files to develop the
application:
1. The EmployeeDatabase.xml file holds the data of all employees.
2. Use XPath expressions.
In this application, the apprentices are defined in the trainee namespace while all other employees are defined in the default namespace. This application should count the number of apprentices and print their details on the user console.
1. The EmployeeDatabase.xml file holds the data of all employees.
2. Use XPath expressions.
In this application, the apprentices are defined in the trainee namespace while all other employees are defined in the default namespace. This application should count the number of apprentices and print their details on the user console.
EmployeeDatabase.xml
Define two kinds of namespaces (ap, em) to differ two kinds of employee (apprenctices and employees)
The static NamespaceContext class and its override method was defined to get uri coressponding with the namspace.
Main class
Create the object of Document class to read EmployeeDataBase.xml
Use xpath query to filter all employee with namespace ap (apprentices). The reuslt was loaded into NodeList object.
Displays size of this nodeList. then use loop method to list all employee having namespace ap
Result:
There are 3/4 records of load was loaded and they are records of employees with namespace ap
Không có nhận xét nào:
Đăng nhận xét