Chủ Nhật, 3 tháng 8, 2014

Use TreeWalker to read xml file

Module 6:Create an XML document containing the employee details of an organization. Then create an application, which uses the DOM parser to parse the XML document into a DOM tree and traverses through it. The application should implement the TreeWalker interface to traverse all the nodes present in the DOM tree and print the value of the nodes.

B1:Tạo mới java application,gồm các components sau:


B2:Tạo file Empoyess.xml có nội dung như sau:


B3:Triển khai code trong hàm main

Tạo hàm traversal để hiển thi list





Kết quả:



Nhận xét:  sử dụng treeWalker giúp cho việc truy xuất tới các thẻ 1 bất kỳ cách dễ dàng,và lấy thông tin từ các thẻ đó
-DOM có nhiều tính năng vượt trội hơn hẳn so với SAX
-DOM có câu truc cấy,vì vậy treeWalker được tạo ra để tối ưu hóa cho DOM

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

Đăng nhận xét