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

use DOM to work with XML

Module 1:Create a student list student.xml. Write a program for a teacher to count the number of students in a class. Create a DOM tree for parsing the student.xml. Declare countStudents() function recursively count the number of Student nodes till reaching the last node in the XML document.

B1:Tạo 1 java application,có các thành phần như sau


B2:Tạo file student.xml


B3:Code cho hàm main


Kết quả: ta có 4 thẻ member


Source code:


Module 4:Create an XML document parser application.The application should use a DOM parser to parse an XML document containing the names of employees of an organization, ABC Apparels Ltd, and then print the names of all the employees.

B1:Tạo 1 java application,có các thành phần như sau


B2:Tạo file Employees.xml


B3:Code cho hàm main


Kết quả:ta thu được danh sách các employee


Nhận xét: Việc xử dụng DOM giúp cho việc truy xuất tới các thẻ đơn giản hơn SAX rất nhiều,việc code cũng đơn giản hơn
-Về cách làm việc với DOM tương tự như với SAX

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

Đăng nhận xét