Thứ Ba, 29 tháng 7, 2014

User NodeIterator to read XML file

Demo: 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 NodeInterator interface to traverse through all the nodes present in the DOM tree and print the value of the nodes.

Bước 1: Tạo new project



Bước 2: Tạo file employees.xml

Bước 3: Viết code cho file chạy chương trình


Kết quả:


Demo : https://drive.google.com/file/d/0B-EFzewQLSMDQWhGWVMtUzBudDQ/edit?usp=sharing

Nhận xét
-Giao diện NodeIterator và NodeFilter rất dễ sử dụng, mạnh mẽ
-Traversal có thể chọn lọc các nội dung của tài liệu để hiện thị rõ ràng
- Phương thức nextNode () của iterater trả về node đầu tiên của cây con; trong nhiều trường hợp , khi các node của cây con không tìm thấy nữa, thì phương thức nextNode () sẽ trả về null. Điều này giúp chương trình làm việc với file XML dễ dàng và an toàn.


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

Đăng nhận xét